orchestra / resources
此包已被废弃且不再维护。未建议替代包。
[已弃用] Orchestra 平台的资源组件
v3.2.0
2015-12-20 15:47 UTC
Requires
- php: >=5.5.0
- orchestra/routing: ~3.2
- orchestra/support-facades: ~3.2
Requires (Dev)
- illuminate/events: ~5.2
- illuminate/http: ~5.2
- mockery/mockery: ^0.9.1
- orchestra/facile: ~3.2
Suggests
- laravel/framework: Allow using orchestra/resources component outside of Orchestra Platform (~5.2).
- orchestra/foundation: Allow using orchestra/resources with Orchestra Platform (~3.2).
README
资源组件是一个可选的临时路由管理器,允许扩展开发者在不接触 Orchestra Platform 2 的情况下添加 CRUD 接口。其理念是允许将控制器映射到 Orchestra Platform 管理员界面中的特定 URL。
目录
版本兼容性
Laravel | 资源 |
---|---|
4.0.x | 2.0.x |
4.1.x | 2.1.x |
4.2.x | 2.2.x |
5.0.x | 3.0.x |
5.1.x | 3.1.x |
~5.2 | 3.2.x |
安装
通过 composer 安装,只需在您的 composer.json
文件中添加以下内容
{ "require": { "orchestra/resources": "~3.0" } }
然后从终端运行 composer install
。
快速安装
上述安装也可以通过以下命令简化
composer require "orchestra/resources=~3.0"
配置
在 config/app.php
中添加 Orchestra\Resources\ResourcesServiceProvider
服务提供者。
'providers' => [ // ... Orchestra\Resources\ResourcesServiceProvider::class, ],
别名
您可能希望将 Orchestra\Support\Facades\Resources
添加到 config/app.php
中的类别名中
'aliases' => [ // ... 'Resources' => Orchestra\Resources\Facade::class, ],
使用
添加资源
通常我们会对一个扩展和资源进行标识以方便使用,然而 Orchestra Platform 仍然允许单个扩展在需要时注册多个资源。
use Orchestra\Support\Facades\Foundation; Event::listen('orchestra.started: admin', function () { $robots = Resources::make('robotix', [ 'name' => 'Robots.txt', 'uses' => 'Robotix\ApiController', 'visible' => function () { return (Foundation::acl()->can('manage orchestra')); }, ]); });
名称 | 使用 |
---|---|
name | 一个用于引用资源的名称或标题。 |
uses | 控制器路径,您可以用 restful: (默认)或 resource: 前缀来表示 Orchestra Platform 应如何处理控制器。 |
visible | 选择是否将资源包含在 Orchestra Platform 管理员界面菜单中。 |
Orchestra Platform 管理员界面现在会在“扩展”旁边显示一个新标签页,您现在可以导航到可用的资源。
添加子资源
单个资源可能需要多个操作(或控制器),我们允许通过分配子资源来使用此功能。
$robots->route('pages', 'resource:Robotix\PagesController');
也支持嵌套资源控制器
$robots['pages.comments'] = 'resource:Robotix\Pages\CommentController';
从资源返回响应
将控制器映射为Orchestra平台资源与任何其他控制器没有区别,除了布局使用了Orchestra平台管理员界面。您可以使用视图
、响应
和重定向
,就像没有集成Orchestra平台一样正常使用。