Reputation: 185
If we just create a 404.blade.php
page in resources/views/error
it will work fine, but Auth() won't work on 404 page, to solve that if we follow the solution available on stackoverflow the Laravel auth errors will stop working. I use the following solution to do the work.
Upvotes: 3
Views: 8692
Reputation: 87
Not sure if this will help. Laravel has a PHP artisan command to publish error pages. Laravel Custom HTTP Error Pages
After you run this artisan command use Route:fallback()
method as @KFoobar suggested. If you use a closure function, no need to use a controller. Make sure to add the below route at the ends of your routes file.
//Fallback/Catchall Route
Route::fallback(function () {
return view('errors.layout');
});
Upvotes: 1
Reputation:
For Laravel 5.6 and later, you can use fallback
in your routes\web.php
:
Route::fallback('MyController@show404');
It works as an "catch all"-route.
Upvotes: 3
Reputation: 394
Write below code in your Exceptions/Handler.php
if($this->isHttpException($exception)){
if(view()->exists('errors.'.$exception->getStatusCode())){
$code = array('status'=>$exception->getStatusCode());
return response()->view('errors.404',compact('code'));
}
}
Now create a new file in your view i.e errors/404;
Now in code array you can pass dynamic values
Upvotes: 0
Reputation: 12391
Create custom view
resources/views/errors/404.blade.php
in route.php
Route::any('{catchall}', 'PageController@notfound')->where('catchall', '.*');
create PageController
and add this function
public function notfound()
{
return view('errors.404');
}
Upvotes: 7