I am trying to redirect in Laravel like this:
in my controller:
$state = false;
return redirect()->route('newPr')->with('errorMessageDuration', 'error', $state);
and in my view I try to get it like this:
<input id="PrId" type="text" value="{{ isset($state) ? $state : '' }}">
but somehow it does not work, it keeps being empty.
I want it to be saved permanently.
Use sessions.
And in the view:
Try using the session to display it,
Use
withErrors()
with an associative array instead, like so:Then you can simply use the $errors variable in your view.
From the docs:
with
method takes 2 parameters. The 1st one being thekey
and 2nd onevalue
Or if the 1st parameter is an array itskey
will be thekey
andvalue
will be thevalue
.So in your case you can do
->with('state', $state)
Or->with(compact('state'))
with
method will flush this value to thesession
so in order to retrieve the value you need to get it fromsession
like thissession('state')
You can pass any value in this manner.
You can't send variable with redirect, but if you want try with session.
Take a look at my old answer here: Trying to pass a variable to a view, but nothing is shown in the view - laravel