Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lako's avatar
Level 2

How to access cookie value in Laravel blade template

Hi guys Now I 've set some cookie in my laravel project(laravel 5.1) I wanted to use cookie value like below.

<div class="mail-form">
            {{-- Error Message --}}
            @if (Session::has('error'))
                <div class="error">{{ Session::get('error') }}</div>
            @endif

            {!! Form::open(['url' => '/branch']) !!}
                <input type="text" name="username" placeholder="Username" value="{{ \Illuminate\Http\Request::cookie('remembered-username') }}" />
                <input type="password" name="password"  class="pass" placeholder="Password" value="{{ \Illuminate\Http\Request::cookie('remembered-password') }}" required=""/>
                <input type="submit" value="Submit">
            {!! Form::close() !!}
            <input type="checkbox" id="checkbox-2" name="remember_me" @if(\Illuminate\Http\Request::cookie(remembered') == 'remembered') checked @endif>
            <span>Remember me</span>
        </div>

By the way, I've got this error.

Non-static method Illuminate\Http\Request::cookie() should not be called statically, assuming $this from incompatible context

How can I use cookie correctly in blade. Thank you for your considering and help.

0 likes
2 replies
bobbybouwmann's avatar
Level 88

@lako Please don't bump your thread if you don't have a reply in an hour... You will get help eventually! Also don't tag people who helped before. Remember that they also have a job and any other person can help you out here as well ;)

Now for your problem. You can use the cookie facade

@if (Cookie::get('remembered') == 'remembered') checked="checked" @endif
5 likes
lako's avatar
Level 2

Thank you! @bobbybouwmann I've fixed under your suggestion. It's correct. Also thanks for your kind advice. I appreciate your friendly hearted. I am new to laracasts.

Thank you again.

1 like

Please or to participate in this conversation.