Laravel Cookies

Sorry, this video is only available to Subscribers

Laravel Cookies

In this video we'll be teaching you just how easy it is to use cookies in your Laravel project.

In order to set a cookie you would need to redirect the user and set a cookie by using the following code:

$ref = 'my cookie value';
return redirect('/')->withCookie('ref', $ref);

If you wanted to set a cookie that lasted forever you would use the following code:

$ref = 'my cookie value';
return redirect('/')->withCookie(cookie()->forever('ref', $ref));

Then in order to get the value of a cookie we would use the following code:

$cookie = $request->cookie('ref');

To learn more about using Laravel cookies you can checkout the laravel official documentation at:

Tags: laravel, cookies, laravel cookies

+1 Sushi Points!

Nice Job! You've just earned 1 Sushi Points for accomplishing

Don't want to see ads? Become a Subscriber ✌️ ×