Reputation: 81
I'm trying to cookie user login values, I grouped in route like this:
Route::group(['middleware' => ['admin']], function () {
Route::post('/admin/addArticle', [
'as' => 'article_save', 'uses' => 'AdminController@saveCover'
]);
Route::get('/admin/introduction', [
'as' => 'introduction', 'uses' => 'AdminController@introduction'
]);
});
AdminController:
$cookie = Cookie::forever('admin', $admin);
Cookie::queue($cookie);
return Redirect::route('introduction')->withCookie($cookie);
Models/Admin:
if (Cookie::has('admin')) {
//echo 'admin is not in session but cookie';
$admin = Cookie::get('admin');
//...
but it's not go in this if never and nothing is saved in cookie !!! Unfortunately I have upgraded to laravel 5.4 of 5.2 and anything is in the wrong way now :(((( please help me!
Upvotes: 1
Views: 1538
Reputation: 44
Laravel is encrypting cookies, so I had to add an exception for them in App\Http\Middleware\EncryptCookies\
:
protected $except = [
'cookie_name'
];
Upvotes: 3
Reputation: 2179
Just change the way you set the cookie to Cookie::queue('admin', $admin);
Upvotes: 0