【问题标题】:information about route resource in laravel 4关于 laravel 4 中路由资源的信息
【发布时间】:2014-06-21 04:39:35
【问题描述】:

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

Route::resource();

怎么用?

【问题讨论】:

标签: php laravel controller routing laravel-4


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-08
    • 1970-01-01
    • 2014-06-27
    • 2013-08-20
    • 2014-02-04
    • 1970-01-01
    • 1970-01-01
    • 2014-02-18
    相关资源
    最近更新 更多