mardi 18 octobre 2016

Laravel 5.1 Sessions not working

I have fresh Laravel 5.1 distribution. The first thing I started from is to extend the Guard class in order to implement my own auth driver. I'm really new with Laravel. So, here is what I did so far.

config/auth.php

'driver' => 'crm',

Providers/AuthServiceProvider.php

   public function boot(GateContract $gate)
    {
        Auth::extend(
            'crm',
            function ($app) {
                $model = $app['config']['auth.model'];
                $provider = new EloquentUserProvider($app['hash'], $model);

                return new CrmGuard($provider, $app->make('session.store'));
            }
        );
    }

Currently, I already have a user id, stored in session array and I can access it via

session_start();
$_SESSION['user_id'];

But I want to use a Laravel build in session management. I'm trying to rewrite user method of Guard class in my CrmGuard class and I need to get those values from session, I was trying like so

$id = $this->session->get('user_id');

and so

session('user_id')

But it always return NULL, what I did wrong? Thank you.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire