0% found this document useful (0 votes)
95 views2 pages

Laravel Auth and Session Tips

This document discusses authentication in Laravel and displaying logout messages. It describes using the built-in auth middleware to restrict routes to authenticated users. It also shows how to logout a user and redirect them to the homepage while flashing a logout message session. Additional information is provided on putting, getting, and checking for session values.

Uploaded by

Owen Luz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
95 views2 pages

Laravel Auth and Session Tips

This document discusses authentication in Laravel and displaying logout messages. It describes using the built-in auth middleware to restrict routes to authenticated users. It also shows how to logout a user and redirect them to the homepage while flashing a logout message session. Additional information is provided on putting, getting, and checking for session values.

Uploaded by

Owen Luz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Redirect to Login if user not logged in

Laravel
Laravel 5.4

Use the built in auth middleware.


Route::group(['middleware' => ['auth']], function() {
// your routes
});
For a single route:

Route::get('profile', function () {
// Only authenticated users may enter...
})->middleware('auth');

Laravel getLogout with Logout Message


public function logout()
{
Auth::logout();

return redirect('/')
->with('message', 'You have been logged out');
}

To view message:

{{ Session::get('message') }}

Additional info:

Session::put('key','value');//to put the session value


Session::get('key');//to get the session value

Session::has('key');//to check the session variable exist or not

<div class="alert alert-danger


alert-dismissible">
<button type="button" class="close" data-dismiss="alert" aria-
hidden="true">&times;</button>
<h4><i class="icon fa fa-ban"></i> Alert!</h4>
Danger alert preview. This alert is dismissable. A wonderful
serenity has taken possession of my entire
soul, like these sweet mornings of spring which I enjoy with my
whole heart.
</div>
<div class="alert alert-info alert-dismissible">
<button type="button" class="close" data-dismiss="alert" aria-
hidden="true">&times;</button>
<h4><i class="icon fa fa-info"></i> Alert!</h4>
Info alert preview. This alert is dismissable.
</div>
<div class="alert alert-warning alert-dismissible">
<button type="button" class="close" data-dismiss="alert" aria-
hidden="true">&times;</button>
<h4><i class="icon fa fa-warning"></i> Alert!</h4>
Warning alert preview. This alert is dismissable.
</div>
<div class="alert alert-success alert-dismissible">
<button type="button" class="close" data-dismiss="alert" aria-
hidden="true">&times;</button>
<h4><i class="icon fa fa-check"></i> Alert!</h4>
Success alert preview. This alert is dismissable.
</div>

You might also like