Saturday, February 19, 2022

[FIXED] Error when add CSRF token to Laravel form

Issue

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?


Solution

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,



Answered By - Kalhan.Toress

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.