Laravel 模型数据获取

laravel中总模型可以直接toArray()

在今天立哥review代码的时候提出来的.
原代码:

1
2
3
4
5
6
7
8
$bmlist  = Appointment::all();
$baoming = [];

foreach ($bmlist as $bm) {
$baoming[] = $bm->toArray();
}

return $baoming;

改进后的代码:

1
2
$baoming = Appointment::all()->toArray();
return $baoming;

我只想深深说句 fuck!.