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);
}