php - Call to undefined method Illuminate\Database\Query\Builder::put() -
i developing laravel application poultry farm management.
and here using eloquent return collection of stockegg table, stores data egg stock.
but total stock not present in stockegg table, calculating in loop using initial value of total stock.
here controller:
$stockeggs = \app\stockegg::where('farm_id', '=', $farm)->orderby('date', 'asc')->get(); $current_stock = $initial_stock; foreach($stockeggs $stockegg){ $current_stock = $current_stock + $stockegg->daily_balance; $stockegg->put('total_stock', $current_stock); }
but error:
(1/1) badmethodcallexception call undefined method illuminate\database\query\builder::put()
i have included following line @ top of mu controller:
use illuminate\support\collection;
put
not method eloquent. should write code this.
foreach($stockeggs $stockegg){ $current_stock = $current_stock + $stockegg->daily_balance; $stockegg->total_stock = $current_stock; $stockegg->save(); }
for more info https://laravel.com/docs/5.4/eloquent#updates
Comments
Post a Comment