jeudi 3 mars 2016

how to check if user is logged in by his session in route and then call controller method in laravel?

I'm using Laravel 5.2 and i've just started working on it. i want to check user session in routes file, so that if session is set he can visit dashboard otherwise redirect to login page. i've used following code for this but it's not working. it's not giving any error and not redirecting him to login page. anyhow if i write same code in controller functioin, it work fine.

Route::group(['middleware' => ['web']], function () {
    Route::get('dashboard/index', ['uses' => 'DashboardController@index'], function() {
    $value = $request->session()->get('name', 'not_loggin');
    if ($value == 'not_loggin') {
        return redirect('/user/login');
    }
    });
});

it also didn't worked if i write it in constructer.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire