Error Handling - Laravel 11.x - The PHP Framework For Web Artisans

PHOTO EMBED

Mon Jan 06 2025 06:23:59 GMT+0000 (Coordinated Universal Time)

Saved by @Sifat_H

use Illuminate\Http\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
 
->withExceptions(function (Exceptions $exceptions) {
    $exceptions->render(function (NotFoundHttpException $e, Request $request) {
        if ($request->is('api/*')) {
            return response()->json([
                'message' => 'Record not found.'
            ], 404);
        }
    });
})
content_copyCOPY

https://laravel.com/docs/11.x/errors