I manage to handle this by extending Lumen Auth like this :
Extends the Guard class.
<?php namespace App\Auth;
use App\Models\Consumer;
use Illuminate\Auth\Guard;
class ApiGuard extends Guard
{
protected $consumer = null;
public function consumer()
{
return $this->consumer;
}
public function setConsumer($consumer_id)
{
$this->consumer = Consumer::find($consumer_id);
}
}
Create a new AuthServiceProvider in order to use our new ApiGuard class.
<?php namespace App\Providers;
use App\Auth\ApiGuard;
use Illuminate\Auth\AuthServiceProvider as ServiceProvider;
use Illuminate\Auth\EloquentUserProvider;
class AuthServiceProvider extends ServiceProvider
{
public function boot()
{
$this->app['auth']->extend('eloquent', function ($app)
{
$model = $app['config']['auth.model'];
$provider = new EloquentUserProvider($app['hash'], $model);
return new ApiGuard($provider, $this->app['session.store']);
});
}
}
Then register the service provider in our app.php
$app->register('App\Providers\AuthServiceProvider');
Then I can use this in my Auth middleware :
Auth::setConsumer($user_token->consumer_id);
And this in my controllers
$consumer = Auth::consumer()
If anyone has a better solution, I'd like to know :)