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">×</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">×</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">×</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">×</button>
<h4><i class="icon fa fa-check"></i> Alert!</h4>
Success alert preview. This alert is dismissable.
</div>