I'm attempting to create a simple data display form in Laravel to display contact details given phone number. Phone number is passed in to the form from the URL (route). If the URL is does not include a phone number all the fields of the form should be empty string. To achieve this I just check if the URL is called without a phone number ($number) and if so, create an associative array with the correct keys and empty strings as values
class InboundCallController
{
public function inboundCall($number=null){
if($number==null) {
$contact=array(
"id"=>"",
"registration_no"=>"",
"title"=>"",
"firstname"=>"",
"lastname"=>"",
"primary_contact"=>"",
"secondary_contact"=>"",
"email"=>"",
"gender"=>"",
"address_line1"=>"",
"address_line2"=>"",
"city_state_province"=>"",
"zip"=>"",
"country"=>"");
return view('InboundCall')
->with('number',null)
->with('contact',$contact);
}
$contact=$this->retrieveContact($number);
return view('InboundCall')
->with('number',$number) //CLI passed from soft-phone
->with('contact',$contact) //Contact details retrieved from db
}
private function retrieveContact($number){
return DB::table('contacts') //Retrieve contact
->where('primary_contact',$number)
->first();
}
}
Trying to get property of non-object (View: /var/www/html/csp/resources/views/InboundCall.blade.php)
On line 37 of the blade I have this:
value="{{$contact->primary_contact}}"