表中laravel没有提交?
我想提交表单到UserController的文件,并调用函数invitebyemail。表中laravel没有提交?
当我点击提交它给我的错误,如“哎呦,看起来像出事了。”
下面是我的文件和代码的结构。
路由文件:
Route::POST('event/inviteforevent', '[email protected]');
Blade.php文件
<form action="{{ route('inviteforevent') }}" method="POST">
<input type="email" class="form-control full-width" id="add-members-event-email" name="email" placeholder="Email address">
<input type="hidden" class="form-control full-width" name="eventid" value="{{ $event->id }}" >
<input type="submit" name="invite" value="submit" />
</form>
UserController的文件:
public function invitebyemail(Request $request){
$event = Event::find($request->eventid);
$timelineId = $event->timeline_id;
$username = Auth::user()->username;
$timelines = Timeline::find($timelineId);
return redirect()->back()->with('message', 'Invitation send to user by email.');
}
的route()
辅助函数预计的路线名称。
Route::post('event/inviteforevent', '[email protected]')->name('inviteforevent');
编辑
运行php artisan serve
和http://localhost:8000
访问您的服务器。您还没有设置Web根目录和laravel URL重写不会与url
和route
方法产生错误的链接一起正常工作。
我做到了这一点,但不是它不工作。“路线:: post('事件/ inviteforevent','UserController @ invitebyemail ') - >名称(' inviteforevent');” –
运行'php工匠路线:清除'一次。加载页面时,请检查表单操作中生成的链接。 – Sandeesh
表格链接像这样“expats_adworlds/public/event/inviteforevent” –
变化
Route::POST('event/inviteforevent', '[email protected]');
到
Route::POST('event/inviteforevent', '[email protected]')->name("inviteforevent");
请航线将这段代码: -
Route::post('event/inviteforevent', '[email protected]')->name('inviteforevent');
OR
Route::post('event/inviteforevent', ['as' => 'inviteforevent', uses' => '[email protected]']);
我改成了这一点,但它不工作。 –
做到这一点,但又是同样的问题。 –
这样做的PHP工匠缓存:清除,PHP工匠路线:清除,PHP工匠优化,PHP工匠配置:清除 –
除了有人建议路线的变化,你可能需要添加后
{{ csrf_field() }}
<form action="{{ route('inviteforevent') }}" method="POST">
完成但不工作。我卡在这里 –
你是否也改变了路线如下建议? 其他网页是否正常工作? 您能否启用日志并上传完整的错误? – Nikolas
TokenMismatchException在VerifyCsrfToken.php行68.错误消息。 –
你必须添加{{ csrf_field() }}
这是建议,但一个问题?你的表格名称和ID在你的表格中打开的地方在哪里?这种形式如何知道你想要添加数据的表格? 你必须添加$events
和$events->id
到你的表格
专业提示:启用调试通过你的'.env'文件来获得有意义的错误信息,而不是“哎呀,出事了”。 (假设你正在使用V5 +) –