laravel relationship retrieve data

Solutions on MaxInterview for laravel relationship retrieve data by the best coders in the world

showing results for - "laravel relationship retrieve data"
Alexander
02 Jul 2019
1$roles = User::find(1)->roles;
2#this works perfectly fine
3#But if you retrieve data with 'where()' and 'get()'.. 
4#then the result is a collection rather than a single item
5
6$users = User::where('Last_name', 'specter')->get();
7$roles = $users[0]->roles;
8