Filter Remove Sessions

Submitted by hellossx - 9 years ago

This filter will prevent the route from having sessions enabled. Very useful for API calls and when you don't want sessions starting. Blog Post: http://dor.ky/laravel-prevent-sessions-for-routes-via-a-filter/

/*
|--------------------------------------------------------------------------
| No session filter
|--------------------------------------------------------------------------
|
| This filter removes the sessions for a given call
|
*/

Route::filter('session.remove', function()
{
return Config::set('session.driver', 'array');
});

/* Apply to a route */
Route::group(array(
    "prefix" => "api/v1",
    "before" => array("session.remove")
), function() {
    Route::get('/search', 'SearchController@getPerformSearch');
});