如果您使用相同的动词和 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 stuff