Hello I wanted to know how to access and store a property of a gotten object in laravel controller and here is my code:-
$phonebooks = Phonebook::with('client')->get();
$test = $phonebooks->id;
return view('admin.phonebooks.index', compact('phonebooks'))->with('current_time',$current_time);
Here I want to store the id property in $test variable but I get this error:- Property [id] does not exist on this collection instance.
get()method notfirst()->get();would return a collection of objects, use->first()or$test = $phonebooks[0]->id;or a loop.