Laravel 5 check whether a user is logged in
You should use the auth
middleware. In your route just add it like this:
Route::get('pages/mainpage', ['middleware' => 'auth', 'uses' => 'FooController@index']);
Or in your controllers constructor:
public function __construct(){ $this->middleware('auth');}
you can do this directly in your blade code by this way
@if (!Auth::guest()) do this @else do that@endif
use
Auth::check()
more here https://laravel.com/docs/5.2/authentication#authenticating-users in Determining If The Current User Is Authenticated