I am trying to display /views/errors/404.blade.php when you access a URL that does not have a route configured in routes.php, but
Is it possible to use the controller?
I would like to display the variables (for example, displaying the login username) given by the controller in the 404.blade.php.
php laravel
if you just want to see the login username in 404.blade.php
{{ Auth::user()->name}}
Then it's OK.
However, if you want to pass other variables to the template,
Edit app/Exceptions/Handler.php.
use Symphony\Component\HttpKernel\Exception\HttpException; // Add around line 7
protected function renderHttpException (HttpException$e) // Add to Handler Class
{
$status=$e->getStatusCode();
$var="Aiueo";
if(view()->exists("errors.{$status}"){
return response()->view("errors.{$status}", ['exception'=>$e, 'var'=>$var], $status);
} else{
return$this->convertExceptionToResponse($e);
}
}
vendor/larvel/framework/Illuminate/Foundation/Exceptions/Handler.php
You are overriding what you are doing in the parent class in the .
© 2024 OneMinuteCode. All rights reserved.