对不起,如果听起来很奇怪,但是在路线上,我认为我需要做两个操作:
Route::post('booking', 'HomeController@booking');
Route::post('booking', function()
{
return Queue::marshal();
});但是,当然,我得到了一个错误:无效的数据。
但是对于视图的“预订”,我需要调用控制器的方法,同时返回Queue::marshal()
也许我能做到?
非常感谢!
编辑:
以下是HomeController@订票方法:
http://paste.laravel.com/19ej
发布于 2013-11-21 11:40:45
如果使用相同的动词和url定义两条路径,则第二条路径永远不会被触发。
Route::post('booking', 'HomeController@booking'); // Laravel will find this route first
Route::post('booking', function() // so this function will never be executed
{
return Queue::marshal();
});我看到您的HomeController@booking()正在处理一个表单。为什么你可以用另一条路来做这件事?
Route::post('booking/create', 'HomeController@booking');然后将表单action方法更改为指向以下路由:
// this will render <form method="POST" action="http://yourdomain.com/booking/create"
{{ Form::open(array('action' => 'HomeController@booking')) }}这样你就不会有一条路线重叠另一条。
一些与问题无关的建议。看看您的控制器,我注意到您在检查错误时会这样做:
if ( ! $errorCondition) {
// do stuff
} else {
// show errors
}如果像这样编写代码,代码将更容易阅读:
if ($errorCondition) {
// return error
}
// do stuffhttps://stackoverflow.com/questions/20118384
复制相似问题