I'm building a middleware to validate user token for mobile api. This is my middleware
public function handle($request, Closure $next, $guard = null)
{
if(!$request->is('api/v1/login')){
$driver = Driver::where('token',$request->token)->first();
if(!$driver){
return response()->json(['error' => 'invalid_credentials'], 401);
}else{
$request->session()->put('mobileuser', $driver);
}
}
return $next($request);
}
This is my routes.php
Route::group(array('prefix' => 'api/v1','middleware' => ['my.token']), function()
{
Route::post('track/', array('as'=>'api.v1.track.update_position', 'uses'=>'Api\v1\DriverController@update_position'));
});
This is my kernel.php
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
],
'api' => [
'throttle:60,1',
],
'my.token' => [
\App\Http\Middleware\DeliToken::class,
\Illuminate\Session\Middleware\StartSession::class
]
];
Basically i want to validate the token sent in the url, and set session if validated.
But i got this error
RuntimeException in Request.php line 859:
Session store not set on request.
Please help, how do i achieve the above ? Thanks
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1O1A8Qv
via IFTTT
Aucun commentaire:
Enregistrer un commentaire