Laravel render rendering with correct url

So my view users

contains a list of all registered users. It also has a button to delete a specific user, so I created a controller and a route

users/delete/this@somemailaddress.com

      

in my controller UsersController

, i am handling the delete action. The user is deleted and I return to users

with a help success alert

that indicates that the user has been deleted.

$message = "User ".$user. " successfully deleted";
return View::make('users')->with(compact('message')); 

      

which works, a warning is displayed. However, Chrome shows localhost:8000/users/delete/this@somemailaddress.com

that I can figure it out, as I just "render" the view users

within the route users/delete/{email}

. Now that I am really new to Laravel (and so, so please understand). I wonder how to get Chrome to show localhost:8000/users

and still show the message. I'm just confused.

+3


source to share


1 answer


What you are looking for is called "flash messages". Here's an example:

On your controller, you are redirecting the message.

return redirect('users')->with('status', 'User deleted!');

      



After you just have to display the message in the view like this.

@if (session('status'))
    <div class="alert alert-success">
        {{ session('status') }}
    </div>
@endif

      

Here's some more documentation: https://laravel.com/docs/5.4/redirects#redirecting-with-flashed-session-data

+3


source







All Articles