Sorry, this video is only available to Pro accounts.

Upgrade your account to get access to all content.

Laravel Cookies

Created on

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: https://laravel.com/docs/requests

Comments (0)