I am developing a Laravel Application for poultry farm management.
And here I am using eloquent to return a collection of Stockegg table, which stores data about the egg stock.
But as total stock is not present in the Stockegg table, I am calculating it in a loop using the initial value of the total stock.
Here is the controller:
$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);
}
But I get this error:
(1/1) BadMethodCallException
Call to undefined method Illuminate\Database\Query\Builder::put()
I have included the following line at the top of mu controller:
use Illuminate\Support\Collection;