Jonh Doe
Jonh Doe

Reputation: 761

Laravel error in post method of route

I got these routes,

Route::group(['middleware' => ['web']], function () {
    //
    // Route definition for showing the login page
    Route::get('login', function() 
    {    
        // Display a placeholder text to the user
        return '<form action="login" method="post">             
                    Username: <input type="text" name="username"><br>           
                    Password: <input type="password" name="password">           
                    <input type="submit" value="Submit">                    
                </form>';       
    });

    // Route definition for processing the login form
    Route::post('login', function()
    {    
        // Display a placeholder text to the user
        return 'Username:'.$_POST["username"].',Password: '.$_POST["password"];
    });
});

when i goto http://localhost:8000/login I then enter a username and a password however route:post produces this error?

Whoops, looks like something went wrong. 1/1 TokenMismatchException in VerifyCsrfToken.php line 67:

Upvotes: 0

Views: 1185

Answers (2)

Lalit Parkash
Lalit Parkash

Reputation: 42

If you are sending post data and the csrf token not defined in form, then laravel throw the exception as below:

Whoops, looks like something went wrong. 1/1 TokenMismatchException in VerifyCsrfToken.php line 67

If you want to remove the csrf token functionality that is by default provided by the laravel u just put comment in

app/Http/Kernel.php - file line no:20

//\App\Http\Middleware\VerifyCsrfToken::class,

then entire project CSRF (Cross-Site Request Forgery) functionality will not works.

but i suggest u Don't disable CSRF protection. because this is automatically detect weather the request is correct/safe or not an intruder attack.

Upvotes: 0

Jimmy Wijaya
Jimmy Wijaya

Reputation: 67

u need put csrf token inside your form..

<form method="POST" action="login">
{{ csrf_field() }}

<input type="text" name="username">
<input type="password" name="password">

<button type="submit">Submit</button>

</form>

Upvotes: 3

Related Questions