I'm new to laravel. I want to display a custom 404 error depending on requested url.
Example:
site.com/somepage
and
site.com/admin/somepage
I've see this answer but it's for laravel 4. I can't find the equivalent answer for Laravel 5.1
Please help. Thanks!
-- ANSWER --
My code based on suggestion by Abdul Basit
//Handle Route Not Found
if ($e instanceof NotFoundHttpException) {
//Ajax Requests
if ($request->ajax() || $request->wantsJson()) {
$data = [
'error' => true,
'message' => 'The route is not defined',
];
return Response::json($data, '404');
} else {
//Return view
if (Request::is('admin/*')) {
return Response::view('admin.errors.404', array(), 404);
} else {
return Response::view('errors.404', array(), 404);
}
}
}
//Handle HTTP Method Not Allowed
if ($e instanceof MethodNotAllowedHttpException) {
//Ajax Requests
if ($request->ajax() || $request->wantsJson()) {
$data = [
'error' => true,
'message' => 'The http method not allowed',
];
return Response::json($data, '404');
} else {
//Return view
if (Request::is('admin/*')) {
return Response::view('admin.errors.404', array(), 404);
} else {
return Response::view('errors.404', array(), 404);
}
}
}