I am handling the HttpNotFoundException and want to when redirecting back with an error message, but it does not display the error message? can anybody help me with it? this is my Handler class render method
public function render($request, Throwable $e)
{
if($e instanceof NotFoundHttpException){
return back()->withErrors(['message' => 'any message']);
}
return parent::render($request, $e);
}
and my login page
@if (Session::has('message'))
<h1>{{ Session::get('message') }}</h1>
@endif
@error('message')
<div role="alert">
<button type="button" data-dismiss="alert" aria-label="Close"
style="text-align: left;">
<span aria-hidden="true">×</span>
<span >Close</span>
</button>
<strong>{{ $message }}</strong>
</div>
@enderror
CodePudding user response:
I have found the solution in here.
just added \Illuminate\Session\Middleware\StartSession::class,
to middleware array of kernel.php
Thanks from all.