Answers for "laravel api return 404"

PHP
1

laravel api form request validation 404

Set an "Accept": "application/json" Request Header
 -- OR --
force the default response behavior by sepcifying the response() method
in your own CustomFormRequest class:
// -- example -- //
public function response(array $errors)
{
    // Always return JSON.
    return response()->json($errors, 422);
}
Posted by: Guest on February-20-2021
0

404 json laravel

To do that, we need to add this logic to the app/Exceptions/Handler.php class:

use Illuminate\Database\Eloquent\ModelNotFoundException;

// ...

public function render($request, Exception $exception)
{
    if ($exception instanceof ModelNotFoundException && $request->wantsJson()) {
        return response()->json(['message' => 'Not Found!'], 404);
    }

    return parent::render($request, $exception);
}
Posted by: Guest on May-08-2020
0

laravel api error return homepage

// add this header on your postman
header : application/json
Posted by: Guest on September-15-2021

Browse Popular Code Answers by Language