Reputation: 167
I've been searching and asking around, but i can't find what i am looking for, or anything similair.
I am looking for a way to pass along certain settings for a user. I have a menu in my back-end which the user can narrow or keep wide. Standard the menu is wide. If a user devides to use the narrow menu, and goes to another page, the menu 'resets' to the default wide state. I'd like to pass along this 'setting' with the user.
I know i have to make a cookie. but what else?? no idea.
!IMPORTANT! I am NOT looking for straight answers (which wont teach me anything) I am looking for suggestions on how to do this and if possible a website attached containing some explanation.
Like i said, i know how to make a cookie, but i do not know how to attach it to whatever.
Upvotes: 0
Views: 1785
Reputation: 111899
The best option to use cookies using queue
method because cookie will be automatically added to response.
You can create multiple cookies for one user but you cannot put optional / different values.
If user will change menu to narrow, you should save cookie with value for example 1, and if he wants menu to be wide again, you can remove the cookie or set it's value to 2.
Each time you load page, you should check if there's a cookie with selected name and if it's value is 1 or different.
Upvotes: 1
Reputation: 810
Laravel Cookies using
$cookie = Cookie::make('name', 'value', 60);
$response = Response::make('Hello World');
return $response->withCookie($cookie);
or
$cookie = Cookie::make('name', 'value', 60);
$view = View::make('categories.list');
return Response::make($view)->withCookie($cookie);
or
$cookie = Cookie::make('name', 'value', 60);
return Redirect::route('home')->withCookie($cookie);
Upvotes: 1