Laravel version 5.5

This article explains how to save cookie data to a browser and show them to the fronted.

The controller – in our example we’ll show to to get a variable value and store it immediately to a cookie with a given name.

First things first get the cookie functionality we’ll need to import the  cookie facades and the cookieJar, at the top of your controller outside the class declaration, we’ll write:

use Illuminate\Cookie\CookieJar;
use Illuminate\Support\Facades\Cookie;

at the function declaration we send in the cookieJar, which looks like this:

public function example(CookieJar $cookieJar)
{

in that fuction depending on what we’re doing with the function and what it returns we store the cookie like this:

Cookie::queue(Cookie::make('SOME_NAME', $VARIABLE_NAME, 3000));

where SOME_NAME is the name of the cookie wich will be shown on the browser, and $variable_name the variable name of course which you want to store in the cookie.

coockie

After the cookie is saved there is just one think left, showing it on the fronted. using blade:

{{ Cookie::get('SOME_NAME') }}

Where SOME_NAME is the cookie name we declared while saving it from the controller.

20/10/2017
laravel-cookies-large

Working with cookies Laravel

Laravel version 5.5 This article explains how to save cookie data to a browser and show them to the fronted. The controller – in our example […]
17/10/2017

Show database results on all pages using view composer

To demonstrate how to show database results on all views using of course view composer we’ll do a simple counter in our application. What that counter […]
03/10/2017

Fix “Syntax error or access violation: 1071 Specified key was too long;”

Laravel 5.4 made a change to the default database character set, and it’s now utf8mb4 which includes support for storing emojis. This only affects new applications and as […]