2014-06-26 34 views
1

我试图学习Laravel,并且我创建了控制器(使用工匠的php artisan controller:make AlbumController)。然后,我添加了一些功能存在,主要功能parseLaravel的路线没有看到控制器的动作

/** 
* Parse the album. 
* 
* @param int $id 
* @return Response 
*/ 
public function parse($id) 
{ 
    return 'http://api.deezer.com/'.$id; 
} 

routes.php我加

Route::resource('album', 'AlbumController'); 

但是,当我尝试访问parse页面(http://localhost/album/parse/123)Laravel返回throw new NotFoundHttpException();

我做错了什么?

回答

1

你需要的路线更改为

Route::get('album/parse/{id}', '[email protected]'); 

更多带有参数的路由,你可以找到HERE的Laravel文档

并与一些有关Routing with Controllers

一小部分文档内我的路线,让你知道它的外观:

Route::get('/partijen/nieuw', '[email protected]'); 
Route::post('/partijen/nieuw', '[email protected]_new'); 
Route::get('/partijen/edit/{id}', '[email protected]'); 
Route::post('/partijen/edit/{id}', '[email protected]_edit'); 
2

parse不是Laravel的资源管理器中包含的路线。运行php artisan routes以查看您当前的路线结构。

如果你想在你的控制器中使用parse方法,你应该手动定义路由。添加像

Route::get('album/parse/{id}', ['uses' => '[email protected]']); 

到您的路线文件。

顺便说一句,资源控制器可以让您的CRUD路线启动并运行,但是最好的做法是明确定义大部分路由,因为routes.php文件对于您的应用程序是有用的文档,它使它的工作更容易遵循。