Hemraj Pal
Hemraj Pal

Reputation: 164

Laravel 5 POST method is not working

My Laravel get method is working but post method is not working.

controller

public function create(Request $request)
{

    if (Request::isMethod('post'))
    {
        echo 'text';
        exit;
    }

}

blade

<form action="{{route('create')}}" method="POST">
<input name="name" class="form-control" type="text">    
<input name="email" class="form-control" type="email">  
<input type="submit" class="btn btn-primary btn-lg btn-block" name="submit">
</form>

route

Route::post('/create', 'Tools\PostController@create')->name('create');

error

The page has expired due to inactivity. Please refresh and try again.

Upvotes: 0

Views: 1795

Answers (1)

Suraj Rana
Suraj Rana

Reputation: 70

You are getting "The page has expired due to inactivity. Please refresh and try again" because you are not passing csrf token with the post request.

By default laravel reject any post request without the csfr token in the request.

Try this:

In your blade file include one hidden input like this :

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

For more info please refer to the docs

Upvotes: 1

Related Questions