0

对不起,如果听起来很奇怪,但是在路线中,在我看来,我需要做两个操作:

Route::post('booking', 'HomeController@booking');
Route::post('booking', function()
{
    return Queue::marshal();    
});

但是当然这样做我会得到一个错误:无效数据。

然而对于视图“预订”的帖子,我需要调用控制器的方法,同时返回Queue::marshal()

也许我可以做到这一点?

非常感谢你!

编辑:

这是 HomeController@booking 方法:

http://paste.laravel.com/19ej

4

1 回答 1

1

如果您使用相同的动词和 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
于 2013-11-21T11:40:45.443 回答