Laravel Cookie Example | Set and Get Cookie in Laravel

Hello Artisan

In this tutorial i will discuss about laravel cookie. In laravel the cookie function creates a new cookie instance. In this tutorial we will see how we can create that mean set cookie and then get that cookie in laravel. 

To simply set and get cookie in laravel follow that code.

$cookie = cookie('name', 'value', $minutes);

Look, cookie take three parameter, first is cookie_name, second is its value that mean data and third is its life_time. So now simply create it.

public function setCookie(Request $request) {

    Cookie::queue('name', $request->test, 10);

    return view('home');
 }

Here Cookie::queue($cookie_name, $data, $life_time_of_this_cookie);

And simply print cookie where you want to show data

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