dro60731
2018-06-11 15:05
浏览 126
已采纳

Laravel 5 POST方法不起作用

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.

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douxin5953 2018-06-11 17:16
    已采纳

    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

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题