we are trying to get the value sent with the redirect method in blade template in laravel.
Here is how my return
statement looks like:
public function movetotrash($id){
$page = Pages::where('id', $id) -> first();
$page -> active = 0;
//$page -> save();
//return redirect()->route('pages.index')->with('trash','Page Moved To Trash');
return redirect('pages')->with('trash','Page Moved To Trash');
}
Now once its redirect to pages
it creates are URL like this http://localhost:8888/laravelCRM/public/pages .
Then i want to print the message to user that "Page is moved to trash" with $trash variable. For which i used this :
@if(isset($trash) ))
<div class="alert alert-error">
{{ $trash }}<br><br>
</div>
@endif
What should i do to print the value?
Thank you! (in advance)
The with method flashes data to the session which is only accessible in the next request. So you can retrieve it from the session like this:
@if(session()->has('trash'))
<div class="alert alert-error">
{{ session()->get('trash') }}
</div>
@endif
In redirect with value pass as session flash,so you need to check value like that
@if(session()->has('trash'))
then you can show like this
{{ session('trash') }}
You can send data from controller like this,
You have to assign the message into variable
$trash = Page Moved To Trash';
return redirect('pages')->with('trash');
and then in view, use like this.
@if(session($trash) ))
<div class="alert alert-error">
{{ session($trash) }}<br><br>
</div>
@endif
The data will store in session and we can use it on redirect page
Hope this will help :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.