Answers for "laravel relationship retrieve data"

PHP
0

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;
Posted by: Guest on September-09-2021

Code answers related to "laravel relationship retrieve data"

Browse Popular Code Answers by Language