disableSearchSyncing(); $entity = $this->getModel()->create( $this->getRequest('store')->all() ); $this->searchable($entity); $message = trans('admin::messages.resource_created', ['resource' => $this->getLabel()]); if (request()->query('exit_flash')) { session()->flash('exit_flash', $message); } if (request()->wantsJson()) { return response()->json( [ 'success' => true, 'message' => $message, 'product_id' => $entity->id, ], 200 ); } return redirect()->route("{$this->getRoutePrefix()}.index") ->withSuccess($message); } /** * Show the form for editing the specified resource. * * @param int $id * * @return Factory|View|Application */ public function edit($id): Factory|View|Application { $entity = $this->getEntity($id); $productEditResource = new ProductEditResource($entity); return view("{$this->viewPath}.edit", [ 'product' => $entity, 'product_resource' => $productEditResource->response()->content(), ] ); } /** * Update the specified resource in storage. * * @param int $id */ public function update($id) { $entity = $this->getEntity($id); $this->disableSearchSyncing(); $entity->update( $this->getRequest('update')->all() ); $entity->withoutEvents(function () use ($entity) { $entity->touch(); }); $productEditResource = new ProductEditResource($entity); $this->searchable($entity); $message = trans('admin::messages.resource_updated', ['resource' => $this->getLabel()]); if (request()->query('exit_flash')) { session()->flash('exit_flash', $message); } if (request()->wantsJson()) { return response()->json( [ 'success' => true, 'message' => $message, 'product_resource' => $productEditResource, ], 200 ); } } }