繁体   English   中英

"Laravel Illuminate\\Database\\Eloquent\\Collection"

[英]Laravel Illuminate\Database\Eloquent\Collection

我通常使用 Eloquent Laravel 单独选择我的项目

$b = Booking::where("id","=",$id)->get();

使用toArray()函数,您就可以开始了,

$bs = Booking::where("date","=",$today)->get()->toArray();

现在,您将拥有从DB返回的数据数组。

你可以这样做:

$bs = Booking::where("date","=",$today)->get();
foreach ($bs as $i=>$b) {
    $bs2[] = collect([$b]);
}

这将为您提供一组Illuminate\\Support\\Collection集合,每个集合只有一个。

如果需要Illuminate\\Database\\Eloquent\\Collection集合:

$bs2[] = new \Illuminate\Database\Eloquent\Collection([$b]);

$bs = Booking::where("date","=",$today)->get();

$new_bs = $bs->toArray;

试试这个,它的工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM