Laravel中路由的顺序是否有影响?
我创建了以下路由:
Route::get('authors/new', array('as'=>'new_author', 'uses'=>'AuthorsController@getNew'));
Route::get('authors/{id}', array('as'=>'author', 'uses'=>'AuthorsController@getView'));
在作者控制器中,我有以下内容:
public function getView($id)
{
return View::make('authors.view')
->with('title', 'Author View Page')
->with('author', Author::find($id));
}
public function getNew()
{
return View::make('authors.new')
->with('title', 'Add New Author');
}
当我访问页面localhost/authors/new
时,它能正常工作。
然而,如果我改变路由的顺序,就像这样:
Route::get('authors/{id}', array('as'=>'author', 'uses'=>'AuthorsController@getView'));
Route::get('authors/new', array('as'=>'new_author', 'uses'=>'AuthorsController@getNew'));
它不再起作用了,它显示:
Trying to get property of non-object (View: C:\xampp\htdocs\laravel\app\views\authors\view.blade.php)