0

我有

Route::get('/layouttest/{category}/{brand}', array('as' => 'main', 'uses' => 'MainController@showUrls')) ->where(array('category' => '[0-9]+', 'brand' => '[0-9]+'));

哪个工作正常。但我想要一条路由来捕获其他获取请求/layouttest/。例如 when{category}{brand}failed->where条件,或者当它们都没有提供时。我什至无法让它工作,(我已经将 if 放在 routes.php 中的上述路由之后,因为):

Route::get('/layouttest/', 
    array('as' => 'index', 'uses' => 'MainController@index'));

当我请求时,/layouttest/我得到一个NotFoundHttpException.

4

1 回答 1

1

这就是你的做法:

Route::get('/layouttest/{category?}/{brand?}', array('as' => 'main', 'uses' => 'MainController@showUrls'))->where(array('category' => '[0-9]+', 'brand' => '[0-9]+'));

您需要创建两条路由以回退到另一个控制器:

Route::get('/layouttest/{category}/{brand}', array('as' => 'main', 'uses' => 'MainController@showUrls'))->where(array('category' => '[0-9]+', 'brand' => '[0-9]+'));

Route::get('/layouttest/{category?}/{brand?}', array('as' => 'index', 'uses' => 'AnotherController@showUrls'));

只要你把这个放在第二位,你就很好。

于 2013-11-26T17:14:57.373 回答