Laravel Cookies

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.


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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.

Method 2

Laravel Cookies using

$cookie = Cookie::make('name', 'value', 60);
$response = Response::make('Hello World');

return $response->withCookie($cookie);


$cookie = Cookie::make('name', 'value', 60);
$view = View::make('categories.list');

return Response::make($view)->withCookie($cookie);


$cookie = Cookie::make('name', 'value', 60);

return Redirect::route('home')->withCookie($cookie);

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x