Laravel 5.4 display cookie value in laravel blade

Viewed 8825

How to display a cookie value in laravel 5.4 blade by interpolation or using conditions ?

Somewhat like this:

    @if (Cookie::get('user_first_name') !== null)
      <a href="javascript:;" id="user_name">
        <i class="fa fa-sign-in" aria-hidden="true"></i>{{ Cookie::get('user_first_name') }}
      </a>
    @else
1 Answers

The way you suggested is correct:

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

Given your comment, you probably did not set the cookie correctly. You may try:

Cookie::queue('user_first_name', 'John', 15);
return view('the-view');
Related