有关laravel 4中路线资源的信息

时间:2014-05-04 23:59:31

标签: php laravel controller routing laravel-4

我是Laravel 4开发的新手,无法在resource类中找到有关Route方法的足够信息

Route::resource();

如何使用它?

1 个答案:

答案 0 :(得分:1)

这是设置API的好方法。它以巧妙的方式实现RESTful。追索控制器路线可以捕获请求并根据RESTful状态将其映射到控制器中的特定方法。

routes.php文件

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/

// Route group for API versioning
Route::group(array('prefix' => 'api/v1'), function() {
    Route::resource('posts', 'PostController');
});

例如:

POST = store() (Create a new entry)
DELETE = destroy($id) (Delete an entry)
GET = index() (Get all entries)
GET = show($id) (Get one entry)
PUT = update($id) (Update an entry)

一个实际的例子: How do I create a RESTful API in Laravel to use in my BackboneJS app