Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

laravel relationship retrieve data

$roles = User::find(1)->roles;
#this works perfectly fine
#But if you retrieve data with 'where()' and 'get()'.. 
#then the result is a collection rather than a single item

$users = User::where('Last_name', 'specter')->get();
$roles = $users[0]->roles;
Source by laravel.com #
 
PREVIOUS NEXT
Tagged: #laravel #relationship #retrieve #data
ADD COMMENT
Topic
Name
2+1 =