Я хочу уменьшить _remain_overall_quantity с inventory
таблицы, используя feed_consumed в consumption
таблице
В состоянии
если $chickenAge
<= 8 <br>Уменьшение произойдет в CBC
, если $chickenAge
> 8 && $chickenAge
<= 20 <br>Уменьшение произойдетв BSC
, если $chickenAge
> 20
Уменьшение будет происходить в BFP
Это мой ConsulationController.php
public function store(Request $request)
{
$this->validate($request, array(
'date_input' => 'required|date',
'feed_consumed' => 'required|numeric',
) );
//declaring values
$chickenAge = 0;
$input= Carbon::parse($request->get('date_input'));
$cycle = Cycle::where('date_of_loading','<=',$input)
->where('date_of_harvest','>=',$input)
->first();
if ($cycle) {
$start = Carbon::parse($cycle->date_of_loading);
$chickenAge = $start->diffInDays($input) ;
}
$inventory = Inventory::where('cycle_id','=',$cycle->id ?? 0)
->first();
$consumption = Consumption::create([
'date_input' => request('date_input'),
'chicken_age' => $chickenAge,
'feed_consumed' => request('feed_consumed'),
'cycle_id' => $cycle->id ?? 0,
'user_id' => Auth::id()
]);
return $consumption;
}
Я не знаю, куда я могу поместить декремент, и я не знаю, что будет оператором if.Вы можете мне помочь?