我刚刚根据Laravel框架编写了一些路线(app\routes.php
),如下所示,
Route::model('cat', 'Cat');
Route::get('/', function()
{
return "All cats";
});
Route::get('/cats', function()
{
$cats = Cat::all();
return View::make('cats.index')->with('cats', $cats);
});
Route::get('/cats/breeds/{name}', function($name)
{
$breed = Breed::whereName($name)->with('cats')->first();
return View::make('cats.index')->with('breed', $breed)->with('cats', $breed->cats);
});
Route::get('/cats/{cat}', function(Cat $cat)
{
return View::make('cats.single')->with('cat', $cat);
});
Route::get('/cats/create', function()
{
return "Cat created.";
});
所有路线都没问题,但/cats/create
除外。
我尝试创建其他两个虚拟路线/dogs
和/dogs/xxx
,而第二个(/dogs/xxx
)无效。
这听起来很奇怪但实际上却发生了。以前有人遇到过这个问题吗?或者你可以给我一些锻炼的提示。
答案 0 :(得分:1)
也许你需要在Route::get('/cats/create'
之前加Route::get('/cats/{cat}
。现在系统会考虑您的create
和{cat}
。