我想知道如何在 laravel 集合中添加额外的列,从数据库返回。例如。
用户模型 User->id User->name
预留模型预留->user_id 预留->id
现在
$users = User::all();
$user_reservation = Reservation::all();
foreach ($users as $user)
{
foreach ($user_reservation as $ur)
{
if ($user->id == $ur->user_id)
{
//Add extra column in to the users model
}
}
}