7

I have a login form in Laravel:

<form class="form-signin" action="{{ URL::route('adminAuthen') }}" method="POST">
    {{ csrf_field() }}
    <h2 class="form-signin-heading">Admin Login</h2>
    <label for="inputUsername" class="sr-only">Email address</label>
    <input type="text" id="inputUsername" name="username" class="form-control" placeholder="Username" required autofocus>
    <label for="inputPassword" class="sr-only">Password</label>
    <input type="password" id="inputPassword" name="password" class="form-control" placeholder="Password" required>
    <button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
</form>

But I always got error when visit this form:

Call to undefined function csrf_field()

How can I fix this bug?

1
  • whats csrf_field ? Commented May 13, 2015 at 7:04

4 Answers 4

19

I think there is no function called csrf_field() in laravel 5, use this instead of that.

<input type="hidden" name="_token" value="{{ csrf_token() }}">

Update 2016-03-17

Laravel introduce csrf_field() in version 5.1

{{ csrf_field() }} this will generate csrf token field,

Sign up to request clarification or add additional context in comments.

1 Comment

I read on the master document page of Laravel and it say about csrf_field() but when I switch to 5.0 document, your answer is correct.
4

You can replace your {{ csrf_field() }} with this:

<input type="hidden" name="_token" value="{{ csrf_token() }}">

You might have misunderstood this because of master documentation page of laravel. I don't why they did that. But this one is what I found to be working on the laravel-5.

Comments

2

Update 2018-10-01

in latest versions of laravel use:

@csrf

and you'll be good to go!
P/S. i use 5.7

Comments

1

The function csrf_field() isn't in regular Laravel 5 yet, even though it's on the master documentation page. You can use the helper csrf_token() instead, see e.g. the helpers documentation, and then build the field yourself from that - or create a template for it, or similar.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.