authorize('createInco', $product); $nutriscores = Nutriscore::cases(); return view('bo.product-incos.create', compact( 'product', 'nutriscores', )); } public function store(StoreProductIncoRequest $request, Product $product): RedirectResponse { $this->authorize('createInco', $product); return DB::transaction(function () use ($request, $product) { $inco = new ProductInco(); $inco->no_art = 1; $inco->fill($request->only( $inco->getFillable() )); $inco->product()->associate($product); if ($inco->saveOrFail()) { return to_route('bo.products.incos.edit', compact('product', 'inco')) ->with('success', trans('crud.messages.has_been_created', [ 'model' => Str::ucfirst(trans_choice('models.classes.product_incos', 1)), ])); } return to_route('bo.products.incos.create') ->with('error', trans('crud.messages.cannot_be_created', [ 'model' => Str::ucfirst(trans_choice('models.classes.product_incos', 1)), ])); }); } public function edit(Product $product, ProductInco $inco): View { $this->authorize('updateInco', $product); $nutriscores = Nutriscore::cases(); return view('bo.product-incos.edit', compact( 'product', 'inco', 'nutriscores', )); } public function update(UpdateProductIncoRequest $request, Product $product, ProductInco $inco): RedirectResponse { $this->authorize('update', $product); return DB::transaction(function () use ($request, $product, $inco) { $inco->fill($request->only( $inco->getFillable() )); if ($inco->saveOrFail()) { return to_route('bo.products.incos.edit', compact('product', 'inco')) ->with('success', trans('crud.messages.has_been_updated', [ 'model' => Str::ucfirst(trans_choice('models.classes.product_incos', 1)), ])); } return to_route('bo.products.incos.edit', compact('product', 'inco')) ->with('error', trans('crud.messages.cannot_be_updated', [ 'model' => Str::ucfirst(trans_choice('models.classes.product_incos', 1)), ])); }); } }