For example, for a normal request, the return method is as follows: {code...} abnormal request. For example, the route is not defined and the request method is not defined. How can I return a json object? It is definitely not appropriate to write it in 404. blade. php, because if it is written in, a string is returned, for example, a normal request. The return method is as follows:
Return response ($ result, $ code); // return json
Abnormal request. For example, the route is not defined and the request method is not defined. How can I return a json object? It is definitely not suitable to write it in 404. blade. php, because if it is written in, a string will be returned.
Reply content:
For example, for a normal request, the return method is as follows:
Return response ($ result, $ code); // return json
Abnormal request. For example, the route is not defined and the request method is not defined. How can I return a json object? It is definitely not suitable to write it in 404. blade. php, because if it is written in, a string will be returned.
InMiddlewareOrApp\Exceptions\HandlerCapture
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
For Middleware
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;public function handle($request, Closure $next) { try { return $next($request); } catch (NotFoundHttpException $e) { return response()->json(['msg'=>'NotFound']); }}