I am currently working in the the project where I've public view i.e. front end and back end for admin purpose.
I want to display separate error page for back end and front end when 404 error is encountered.
Is it possible to do in laravel ?
or Can we make error pages based on namespaces as well ?
Currently I've error pages inside /resources/views/errors/
directory.
Any suggestion are appreciated. If further information needed then feel free to ask.
May not be the best option.
You could separate views based on a current path in Exception Handler's render()
method.
app/Exceptions/Handler.php:
public function render($request, Exception $exception)
{
if ($exception instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException) {
if(str_is('/admin*', request()->path())){
return response()->view('errors.backend.404', [], 404);
} else {
return response()->view('errors.frontend.404', [], 404);
}
}
return parent::render($request, $exception);
}