📜  laravel 关系检索数据 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:46.833000             🧑  作者: Mango

代码示例1
$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;