这是我的部分,我想将表单发送到PostsController中的store函数,但是当我点击Submit时,它显示419页已过期,但是它应该返回到posts页面,并且应该将帖子存储在数据库中。
@section('content')
<form action="{{ action('PostsController@store') }}" method="POST">
<div class="form-group">
<label for="title">Title</label>
<input type="text" id="title" name="title" placeholder="Title">
</div>
<div class="form-group">
<label for="body">Body</label>
<textarea id="body" name="body" placeholder="Body"></textarea>
</div>
<button type="submit" class="btn btn-default">Save</button>
</form>
@endsection
这是我在PostsController中的存储功能
public function store(Request $request)
{
//create post
$post = new Post;
$post->title = $request->input('title');
$post->body = $request->input('body');
$post->save();
return redirect('/posts');
}
答案 0 :(得分:0)
419页已过期错误通常是由csrf令牌问题引起的。
尝试在表单中添加@csrf
:
<form action="{{ action('PostsController@store') }}" method="POST">
@csrf
// etc
</form>