2015-09-28 75 views
0

laravel中的下列字符串究竟是什麼意思?: Route :: resource('user','UserController');什麼意思是字符串Route :: resource('user','UserController');在laravel?

我的想法是在laravel應用程序中查找資源的路由系統,但究竟是什麼意思,每一個字? 單詞'user'是UserController的別名嗎?因爲不是'用戶'可以使用任何其他字

+0

首先你需要了解什麼是[RESTful Web服務](http://www.tutorialspoint.com/restful/)。 –

回答

0

Route::resource是一種通過單個聲明爲控制器方法指定多條路由的方法。例如,對於Route::resource('user', 'UserController');,您可以訪問indexupdatecreateshowstore,如下圖所示editdestroy方法在UserController控制器:

GET <url>/user //points to index() method on UserController 
GET <url>/user/create //points to create() method on UserController 
POST <url>/user //points to store() method on UserController 
POST <url>/user/{userid}/edit //points to edit(userId) method on UserController 

來源:Laravel Docs

+0

好的感謝您的回答和解釋,但然後'用戶'會成爲UserController的別名,因爲它用於訪問UserController的方法? – Joe

+0

@Joe'user'不是UserController的別名。這是URL的一部分,你的控制器的行爲將被稱爲拋出。做一個'php工匠路線:列表',然後你就會明白了。 –

+0

好的,然後那部分URL是一個URI?因爲統一資源標識符(URI)是用於標識資源名稱的字符串。並在laravel文檔中說:通過資源控制器處理的動作:動詞 - 路徑 - 動作 - 路由名稱:GET-/resource/create -create- resource.create(http://laravel.com/docs/4.2/controllers#restful-資源控制器) – Joe

相關問題