From the documentation I see that I simply have to create new blade files within resources/views/errors/ and call them using abort(newhtmlerrorno)
If I want to use blade files from another directory, is this possible or must they be in the base app resources/views/errors/
In your App\Exceptions\Handler class, add this to the start of your render method:
public function render($request, Exception $e)
{
if ($this->isHttpException($e)) {
$statusCode = $e->getStatusCode();
return view("custom.path.{$statusCode}");
}
// ...
}
The error folder on the view path is hardcoded in Illuminate\Foundation\Exceptions\Handler class, which your local app Handler extends. So you can't just configure a custom path without overriding that particular class.
There is a method \Illuminate\Foundation\Exceptions\Handler::registerErrorViewPaths in Laravel 5.8. You can simply override it in your \App\Exceptions\Handler class:
protected function registerErrorViewPaths()
{
$paths = collect(config('view.paths'));
View::replaceNamespace('errors', $paths->map(function ($path) {
return "{$path}/YOUR_CUSTOM_PATH/errors";
})->push(__DIR__.'/views')->all());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With