*/ final class CreateProductInco implements Action { /** * @param \App\Actions\ProductIncos\CreateProductIncoInput $input */ #[\Override] public function __invoke(ActionInput $input): ProductInco { Assert::isInstanceOf($input, CreateProductIncoInput::class); $maxNoArt = ProductInco::query()->max('no_art'); $noArt = $input->no_art ?? (is_numeric($maxNoArt) ? ((int) $maxNoArt) + 1 : 1); if ($noArt <= 0) { $noArt = 1; } $inco = new ProductInco(); $inco->no_art = $noArt; $inco->ingredients = $input->ingredients; $inco->preparation = $input->preparation; $inco->servings = $input->servings; $inco->allergens = $input->allergens; $inco->selling_argument = $input->selling_argument; $inco->nutriscore = $input->nutriscore; $inco->nutriscore_args = $input->nutriscore_args; $inco->nutrition = $input->nutrition; $inco->product()->associate($input->product); $inco->saveOrFail(); return $inco; } }