【发布时间】:2018-01-26 18:02:24
【问题描述】:
我正在开发一个用于家禽养殖场管理的 Laravel 应用程序。
在这里,我使用 eloquent 返回 Stockegg 表的集合,该表存储有关鸡蛋库存的数据。
但由于 Stockegg 表中不存在总库存,我正在使用总库存的初始值循环计算它。
这里是控制器:
$stockeggs = \App\Stockegg::where('farm_id', '=', $farm)->orderBy('date', 'asc')->get();
$current_stock = $initial_stock;
foreach($stockeggs as $stockegg){
$current_stock = $current_stock + $stockegg->daily_balance;
$stockegg->put('total_stock', $current_stock);
}
但我收到此错误:
(1/1) BadMethodCallException
Call to undefined method Illuminate\Database\Query\Builder::put()
我在 mu 控制器的顶部添加了以下行:
use Illuminate\Support\Collection;
【问题讨论】:
标签: php laravel laravel-5 eloquent php-7