bir api yaparken laravel üzerinde ilgili link üzerinden olmayan bir linke girildiğinde json olarak not found değeri geri döndürmesi için App\Exceptions\Handler.php içine girilmesi gereken kod;
1 2 3 4 5 6 7 8 9 |
if (strpos($request->getRequestUri(), '/api/', 0) === 0 && get_class($exception) === NotFoundHttpException::class) { return response()->json([ "status" => 'failure', "error" => 'Page not found', 'code' => 404, "data" => null ], 404); } |