Answers for "laravel try catch integrity duplicate entry"

PHP
0

laravel try catch integrity duplicate entry

according to this sample:


    public function store(ServiceStoreRequest $request, int $id)
    {
        $service = new Serviceable();
        $service->package_id = $id;
        $service->fill($request->all());
        try {
            $service->save();
        } catch (\Exception $exception) {
            return response(array(
                "code"=> 409,
                "error"=>"duplicate " . $exception->getMessage()));
        }
        return response($service);
    }
Posted by: Guest on September-20-2021

Browse Popular Code Answers by Language