> */ protected $dontReport = [ // ]; /** * A list of the inputs that are never flashed for validation exceptions. * * @var array */ protected $dontFlash = [ 'current_password', 'password', 'password_confirmation', ]; /** * Register the exception handling callbacks for the application. * * @return void */ public function register() { // Duplicate constraint $this->renderable(function (QueryException $e, $request) { if ($e->errorInfo[1] == 1062) { return response()->json([ 'error' => true, 'message' => 'Dữ liệu đã tồn tại' ], 422); } }); $this->renderable(function (\Symfony\Component\HttpKernel\Exception\NotFoundHttpException $e, $request) { if (!$request->expectsJson() && !$request->is('v1/*') && !$request->is('api/*')) { return null; } $previous = $e->getPrevious(); if ($previous instanceof \Illuminate\Database\Eloquent\ModelNotFoundException) { $modelClass = $previous->getModel(); $pageType = match ($modelClass) { \App\Models\Product::class => 'service', \App\Models\Customer::class => 'client', \App\Models\Post::class => 'post', default => 'unknown', }; return response()->json([ 'error' => true, 'message' => 'Dữ liệu không tồn tại', 'page_type' => $pageType, ], 404); } return response()->json([ 'error' => true, 'message' => 'API Route not found', ], 404); }); } }