So my view users contains a list of all registered users. It also features a button to delete a specific user, so I created a controller and a route
users/delete/[email protected]
in my controller, UsersController, I handle the delete action. The user gets deleted and I return to users with an success alert which states that the user was deleted.
$message = "User ".$user. " successfully deleted";
return View::make('users')->with(compact('message'));
which works, the alert is displayed. However, Chrome displays localhost:8000/users/delete/[email protected], which I can understand since I just 'make' (render) the users view within the users/delete/{email} route. Now that I'm really new to Laravel (and SO, so please be understanding) I wonder how to get Chrome to display localhost:8000/users and still show the message. I'm merely confused.
What you are looking for is called "flash messages". Here is an example:
On your controller you redirect with the message.
return redirect('users')->with('status', 'User deleted!');
After you simply have to display the message on the view like this.
@if (session('status'))
<div class="alert alert-success">
{{ session('status') }}
</div>
@endif
Here is more documentation: https://laravel.com/docs/5.4/redirects#redirecting-with-flashed-session-data
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With