2017-06-02 107 views
0

我想提交表单到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.'); 
} 
+0

专业提示:启用调试通过你的'.env'文件来获得有意义的错误信息,而不是“哎呀,出事了”。 (假设你正在使用V5 +) –

回答

1

route()辅助函数预计的路线名称。

Route::post('event/inviteforevent', '[email protected]')->name('inviteforevent'); 

编辑

运行php artisan servehttp://localhost:8000访问您的服务器。您还没有设置Web根目录和laravel URL重写不会与urlroute方法产生错误的链接一起正常工作。

+0

我做到了这一点,但不是它不工作。“路线:: post('事件/ inviteforevent','UserController @ invitebyemail ') - >名称(' inviteforevent');” –

+0

运行'php工匠路线:清除'一次。加载页面时,请检查表单操作中生成的链接。 – Sandeesh

+0

表格链接像这样“expats_adworlds/public/event/inviteforevent” –

0

请航线将这段代码: -

Route::post('event/inviteforevent', '[email protected]')->name('inviteforevent'); 

OR

Route::post('event/inviteforevent', ['as' => 'inviteforevent', uses' => '[email protected]']); 
+0

我改成了这一点,但它不工作。 –

+0

做到这一点,但又是同样的问题。 –

+0

这样做的PHP工匠缓存:清除,PHP工匠路线:清除,PHP工匠优化,PHP工匠配置:清除 –

1

除了有人建议路线的变化,你可能需要添加后

{{ csrf_field() }}

<form action="{{ route('inviteforevent') }}" method="POST">

在这里阅读更多:https://laravel.com/docs/5.4/csrf#csrf-introduction

+0

完成但不工作。我卡在这里 –

+0

你是否也改变了路线如下建议? 其他网页是否正常工作? 您能否启用日志并上传完整的错误? – Nikolas

+0

TokenMismatchException在VerifyCsrfToken.php行68.错误消息。 –

0

你必须添加{{ csrf_field() }}这是建议,但一个问题?你的表格名称和ID在你的表格中打开的地方在哪里?这种形式如何知道你想要添加数据的表格? 你必须添加$events$events->id到你的表格