当我单击“提交”按钮提交数据时,它说:
404 |未找到
路线
Route::resource('contactform', 'ContactformController');
刀片
<form class="leave-comment" action="{{ route('contactform.store') }}" method="POST">
<h4 class="m-text26 p-b-36 p-t-15">
Send us your message
</h4>
<div class="bo4 of-hidden size15 m-b-20">
<input class="sizefull s-text7 p-l-22 p-r-22" type="text" name="contact_name" placeholder="Full Name">
</div>
<div class="bo4 of-hidden size15 m-b-20">
<input class="sizefull s-text7 p-l-22 p-r-22" type="text" name="contact_email" placeholder="Email Address">
</div>
<textarea class="dis-block s-text7 size20 bo4 p-l-22 p-r-22 p-t-13 m-b-20" name="contact_message" placeholder="Message"></textarea>
<div class="w-size25">
<!-- Button -->
<button type="submit" class="flex-c-m size2 bg1 bo-rad-23 hov1 m-text3 trans-0-4">
Send
</button>
</div>
</form>
控制器
public function store(Request $request)
{
$request->validate([
'contact_name' => 'required',
'contact_email' => 'required|email',
'contact_message' => 'required'
]);
// send email
Mail::to('test@test.com')->send(new ContactformMail());
}
答案 0 :(得分:1)
每次在应用程序中定义HTML表单时,都应在表单中包含一个隐藏的CSRF令牌字段,以便CSRF保护中间件可以验证请求。您可以使用@csrf
Blade指令生成令牌字段:
<form method="POST" action="/profile">
@csrf
...
</form>