Francis Albert Calas
Francis Albert Calas

Reputation: 51

@csrf is not working in Laravel 5.4

I am following this tutorial on Laravel and I've noticed that I cannot use the @csrf command, but others can use it effectively. But, I can use the {{ csrf_field() }} for the csrf token. I would like to know the reason why. Thanks.

Here's my screenshot on using the @csrf command: Image here

Here's my index.blade.php

       <form action="{{ route('contact.store') }}" method="post">

            @csrf

            <div class="col-md-6 mb-3">
                <label for="username">Username:</label>
                <input class="form-control" type="text" name="name" id="username" placeholder="Username | Email | Phone Number" required>
                <div class="invalid-feedback">
                    Please provide a username
                </div>
            </div>

            <div class="col-md-6 mb-3">
                <label for="password">Password:</label>
                <input class="form-control" type="password" name="name" id="password" placeholder="" required>
                <div class="invalid-feedback">
                    Please provide a password
                </div>
            </div>

            <div class="col-md-6 mb-3">
                <input type="submit">
            </div>
        </form>

Upvotes: 3

Views: 10500

Answers (4)

It&#39;s Diab
It&#39;s Diab

Reputation: 89

if you used to laravel framework version 5.6, 5.5 or less than version 5.5 you should write {{ csrf_field() }}, but if you used to laravel framework version 5.7, 5.8 or bigger than version 5.7 you should write @csrf

Laravel 5.5, 5.6 => write {{ csrf_field() }}

Laravel 5.7, or bigger than 5.7 => write @csrf

Upvotes: 0

Rohit Jadhav
Rohit Jadhav

Reputation: 82

Laravel 5.4 only available refer to this link https://laravel.com/docs/5.4/csrf

{{ csrf_field() }}

And Laravel 5.6 available refer to this link https://laravel.com/docs/5.6/csrf

@csrf

Upvotes: 2

Cadilab
Cadilab

Reputation: 142

As far as I know, there is no @csrf in 5.4, you must use

{{ csrf_field() }}

Instead, @csrf is available in laravel 5.6

Upvotes: 8

Teoman Tıngır
Teoman Tıngır

Reputation: 2866

@csrf argument came to blade with 5.6

you need to use csrf_field() method instead @csrf

for more information check out the docs

Upvotes: 3

Related Questions