蒸馏厂 / 可消耗
可消耗是一个基于laravel 5.*的行政面板。此包为您提供了一些实现,以便添加您应用程序的内容管理系统。您可以覆盖一切。此CMS提供了一些工具,以便您可以轻松且正确地开发内容管理系统。
Requires
- php: >=7.1.3
- distilleries/datatable-builder: 2.14.*
- distilleries/form-builder: 2.13.*
- distilleries/permission-util: 1.10.*
- distilleries/security: 1.1.*
- forxer/gravatar: ~1.2
- illuminate/database: 5.8.*
- illuminate/support: 5.8.*
- illuminate/translation: 5.8.*
- maatwebsite/excel: 3.1.*
Requires (Dev)
- fzaninotto/faker: ~1.4
- mockery/mockery: ~1.0
- orchestra/database: 3.8.*
- orchestra/testbench: 3.8.*
- orchestra/testbench-browser-kit: 3.8.*
- phpunit/phpunit: ~7.0
- 2.24.1
- 2.24.0
- 2.23.0
- 2.22.1
- 2.22.0
- 2.21.3
- 2.21.2
- 2.21.1
- 2.21.0
- 2.20.1
- 2.20.0
- v2.19.2
- 2.19.1
- 2.19.0
- v2.18.9
- 2.18.8
- 2.18.7
- 2.18.6
- 2.18.5
- 2.18.4
- 2.18.3
- 2.18.2
- 2.18.1
- 2.18.0
- 2.17.0
- 2.16.7
- 2.16.6
- 2.16.5
- 2.16.4
- 2.16.3
- 2.16.2
- 2.16.1
- 2.16.0
- 2.15.0
- 2.14
- 2.13.3
- 2.13.2
- 2.13.1
- 2.13.0
- 2.12.0
- 2.11.0
- 2.10.0
- 2.9.5
- 2.9.4
- 2.9.3
- 2.9.2
- 2.9.1
- 2.9.0
- 2.8.1
- 2.8.0
- 2.7.3
- 2.7.2
- 2.7.1
- 2.7.0
- 2.6.14
- 2.6.13
- 2.6.12
- 2.6.11
- 2.6.10
- 2.6.9
- 2.6.8.x-dev
- 2.6.8
- 2.6.7
- 2.6.6
- 2.6.5
- 2.6.4
- 2.6.3
- 2.6.2
- 2.6.1
- 2.6.0
- 2.5.5
- 2.5.4
- 2.5.3
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4.5
- 2.4.4
- 2.4.3
- 2.4.2
- 2.4.1
- 2.4.0
- 2.3.0
- 2.2.6
- 2.2.5
- 2.2.4
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.6.x-dev
- 2.1.6
- 2.1.5.x-dev
- 2.1.5
- 2.1.4
- 2.1.3
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.2
- 2.0.1
- 2.0.0
- 1.3.2
- 1.3.1
- 1.2.0
- dev-scrutinizer-patch-1
- dev-scrutinizer-patch-2
- dev-release/2.19.2
- dev-release/2.18.9
- dev-release/2.18.8
- dev-release/2.20.1
- dev-release/2.19.1
- dev-release/2.18.7
- dev-develop
- dev-dev
- dev-laravel-4
This package is auto-updated.
Last update: 2024-09-11 02:34:09 UTC
README
可消耗
可消耗是一个基于laravel 5.6.*的行政面板。此包为您提供了一些实现,以便添加您应用程序的内容管理系统。您可以覆盖一切。此CMS提供了一些工具,以便您可以轻松且正确地开发内容管理系统。
目录
需求
要使用此项目,您必须安装
- Php 7.1.3或更高版本
- 启用mpcrypt
- Composer https://getcomposer.org.cn/download/
- Sass (
gem install sass
) - NodeJs版本v9.4.0
安装
在您的composer.json中添加
"require": { "distilleries/expendable": "2.*", }
运行composer update
。
将应用程序覆盖添加到bootstrap/app.php
$app = new \Distilleries\Expendable\Fondation\Application( realpath(__DIR__ . '/../') ); $app->bind('path.storage', function ($app) { $path = env('STORAGE_PATH', base_path() . DIRECTORY_SEPARATOR . 'storage'); return $path; });
我添加了一个绑定事件来覆盖存储路径。如果您想覆盖它,只需在您的.env中添加STORAGE_PATH=
。如果您不想覆盖它,只需将其放在您的.env中。
将服务提供程序添加到config/app.php
'providers' => [ /* * Package Service Providers... */ Laravel\Tinker\TinkerServiceProvider::class, Distilleries\FormBuilder\FormBuilderServiceProvider::class, Distilleries\DatatableBuilder\DatatableBuilderServiceProvider::class, Distilleries\PermissionUtil\PermissionUtilServiceProvider::class, Maatwebsite\Excel\ExcelServiceProvider::class, Distilleries\Expendable\ExpendableServiceProvider::class, Distilleries\Expendable\ExpendableRouteServiceProvider::class, ]
并且外观(也在config/app.php
中)替换laravel外观Mail
'aliases' => [ /** * Vendor facade * */ 'FormBuilder' => \Distilleries\FormBuilder\Facades\FormBuilder::class, 'Form' => Collective\Html\FormFacade::class, 'HTML' => Collective\Html\HtmlFacade::class, 'Datatable' => \Distilleries\DatatableBuilder\Facades\DatatableBuilder::class, 'PermissionUtil' => \Distilleries\PermissionUtil\Facades\PermissionUtil::class, 'Excel' => \Maatwebsite\Excel\Facades\Excel::class, ]
用新的外观替换旧的服务外观Mail。
发布配置
php artisan vendor:publish --provider="Distilleries\Expendable\ExpendableServiceProvider"
配置
return [ 'login_uri' => 'admin/login', 'logout_action' => 'Distilleries\Expendable\Http\Controllers\Admin\LoginController@getLogout', 'admin_base_uri' => 'admin', 'config_file_assets' => base_path().'/package.json', 'folder_whitelist' => [ 'moximanager' ], 'listener' => [ '\Distilleries\Expendable\Listeners\UserListener' ], 'mail' => [ 'actions' => [ 'emails.password' ] ], 'menu' => \Distilleries\Expendable\Config\MenuConfig::menu([], 'beginning'), 'menu_left_collapsed' => false, 'state' => [ 'Distilleries\DatatableBuilder\Contracts\DatatableStateContract' => [ 'color' => 'bg-green-haze', 'icon' => 'th-list', 'libelle' => 'expendable::menu.datatable', 'position' => 0, 'action' => 'getIndex' ], 'Distilleries\Expendable\Contracts\OrderStateContract' => [ 'color' => 'bg-grey-cascade', 'icon' => 'resize-vertical', 'libelle' => 'expendable::menu.order_state', 'position' => 1, 'action' => 'getOrder' ], 'Distilleries\Expendable\Contracts\ExportStateContract' => [ 'color' => 'bg-blue-hoki', 'icon' => 'save-file', 'libelle' => 'expendable::menu.export', 'position' => 2, 'action' => 'getExport' ], 'Distilleries\Expendable\Contracts\ImportStateContract' => [ 'color' => 'bg-red-sunglo', 'icon' => 'open-file', 'libelle' => 'expendable::menu.import', 'position' => 3, 'action' => 'getImport' ], 'Distilleries\FormBuilder\Contracts\FormStateContract' => [ 'color' => 'bg-yellow', 'icon' => 'pencil', 'libelle' => 'expendable::menu.add_state', 'position' => 4, 'action' => 'getEdit' ], ] ];
菜单
我使用一个函数来轻松合并默认组件与应用程序的组件。
默认情况下,您可以在左侧菜单中找到
- 电子邮件
- 电子邮件列表
- 添加电子邮件
- 用户
- 用户列表
- 添加用户
- 角色
- 角色列表
- 添加角色
- 权限
- 关联权限
- 服务列表
- 添加服务
- 同步所有服务
- 语言
- 语言列表
- 添加语言
默认情况下,您可以在菜单任务中找到
- 生成新的组件
- 同步所有服务
要添加新项目很容易
'menu' => \Distilleries\Expendable\Config\MenuConfig::menu([ 'left' => [ [ 'icon' => 'send', 'action' => 'Admin\ContactController@getIndex', 'libelle' => 'Contact', 'submenu' => [ [ 'icon' => 'th-list', 'libelle' => 'List of Contact', 'action' => 'Admin\ContactController@getIndex', ], [ 'icon' => 'pencil', 'libelle' => 'Add Contact', 'action' => 'Admin\ContactController@getEdit', ] ] ], ], 'tasks' => [ [ 'icon' => 'console', 'action' => 'Admin\TestController@getIndex', 'libelle' => 'Test', ], ] ], 'beginning'),
方法\Distilleries\Expendable\Config\MenuConfig::menu
接受两个参数
- 包含菜单内容的数组
['left'=>[],'tasks'=>[]]
- 第二个参数是一个字符串
beginning
或end
,用于定义合并的方向。
左侧菜单示例
任务菜单示例
状态
状态是您控制器的一部分,您在其中定义一系列操作。默认情况下,我实现了四个状态
- 数据表
- 订单
- 导出
- 导入
- 表单
要显示状态菜单,我提供了一个接口类Distilleries\Expendable\Contracts\StateDisplayerContract
。
$this->app->singleton('Distilleries\Expendable\Contracts\StateDisplayerContract', function ($app) { return new StateDisplayer($app['view'],$app['config']); });
此类检查控制器上的接口使用情况,并使用配置expendable::state
显示标志和状态名称。如果您想更改状态显示,只需提供一个新的类来实现契约Distilleries\Expendable\Contracts\StateDisplayerContract
。
为了显示所有元素,我使用了一个布局管理器。您可以重写它来显示您想要的。
$this->app->singleton('Distilleries\Expendable\Contracts\LayoutManagerContract', function ($app) { return new LayoutManager($app['config']->get('expendable'), $app['view'], $app['files'], app('Distilleries\Expendable\Contracts\StateDisplayerContract')); });
1. 数据表
数据表状态用于显示内容列表,如果需要,还可以进行筛选。要使用它,您必须实现接口Distilleries\DatatableBuilder\Contracts\DatatableStateContract
。
public function getIndexDatatable(); public function getDatatable();
getIndexDatatable
用于初始化数据表。getDatatable
用于获取JSON数据。
您可以使用特性
use \Distilleries\Expendable\States\DatatableStateTrait;
在这个特性中,您有一个用于显示数据表和数据的泛型实现。此特性需要使用您控制器的两个属性
$datatable
,它是一个EloquentDatatable
实例(来自DatatableBuilder)。model
,它是一个Model
实例(来自laravel)。
在构造函数中注入它们
public function __construct(\Address $model, AddressDatatable $datatable) { $this->datatable = $datatable; $this->model = $model; }
2. 排序
向组件添加基本排序功能。
处理控制器
- 必须实现
\Distilleries\Expendable\Contracts\OrderStateContract
- 方法在
\Distilleries\Expendable\States\OrderStateTrait
中实现
处理模型
- 必须实现
\Distilleries\Expendable\Contracts\OrderContract
方法
orderLabel()
必须返回在订单页面显示的字符串(使用模型属性)orderFieldName()
必须返回模型持久化排序的字段名称
3. 导出
导出状态是从模型之间导出数据。要使用它,您必须实现接口Distilleries\Expendable\Contracts\ExportStateContract
。
public function getExport(); public function postExport();
getExport
用于显示选择日期和导出类型的表单。postExport
处理导出并返回文件。
您可以使用特性
use \Distilleries\Expendable\States\ExportStateTrait;
在这个特性中,您有一个用于导出数据的泛型实现。此特性需要使用您控制器的属性
model
,它是一个Eloquant
实例(来自laravel)。
在构造函数中注入它们
public function __construct(\Address $model) { $this->model = $model; }
您可以通过添加这些方法到服务提供程序并更改实例化的类来更改提供数据导出的类。
$this->app->singleton('Distilleries\Expendable\Contracts\CsvExporterContract', function ($app) { return new CsvExporter; }); $this->app->singleton('Distilleries\Expendable\Contracts\ExcelExporterContract', function ($app) { return new ExcelExporter; }); $this->app->singleton('Distilleries\Expendable\Contracts\PdfExporterContract', function ($app) { return new PdfExporter; });
4. 导入
导入状态是将数据从文件导入到模型。要使用它,您必须实现接口Distilleries\Expendable\Contracts\ImportStateContract
。
public function getImport(); public function postImport();
getImport
用于显示提供文件的表单。postImport
处理导入并返回。
您可以使用特性
use \Distilleries\Expendable\States\ImportStateTrait;
在这个特性中,您有一个用于导出数据的泛型实现。此特性需要使用您控制器的属性
model
,它是一个Eloquant
实例(来自laravel)。
在构造函数中注入它们
public function __construct(\Address $model) { $this->model = $model; }
您可以通过在服务提供程序中添加这些方法并更改实例化的类来更改提供数据导入的类。
$this->app->singleton('CsvImporterContract', function ($app) { return new CsvImporter; }); $this->app->singleton('XlsImporterContract', function ($app) { return new XlsImporter; }); $this->app->singleton('XlsxImporterContract', function ($app) { return new XlsImporter; });
5. 表单
表单状态为您提供了一个部分来添加或编辑元素,以及一个部分来查看元素而不编辑。
要使用它,您必须实现接口Distilleries\FormBuilder\Contracts\FormStateContract
。
public function getEdit($id); public function postEdit(); public function getView($id);
getEdit
用于显示用于编辑或添加新项目的表单。postEdit
处理保存或更新。getView
显示不可编辑的表单。
您可以使用特性
use \Distilleries\Expendable\States\FormStateTrait;
在这个特性中,您有一个用于显示表单、保存和显示视图的泛型实现。此特性需要使用您控制器的两个属性
model
,它是一个Eloquant
实例(来自laravel)。form
,它是一个Form
实例(来自FormBuilder)。
在构造函数中注入它们
public function __construct(\Address $model, AddressForm $form) { $this->form = $form; $this->model = $model; }
组件
组件只是控制器、表单、数据表、模型的组合。要创建新的组件,您可以进入/admin/component/edit
并填写表单,或者使用命令行
php artisan expendable:component.make app/controllers/Admin/TestController
您可以使用帮助来检查选项。
在后台,您有所有这些选项
要了解所有字段类型,您可以查看文档。
Admin BaseComponent
默认情况下,如果您选中所有由 Distilleries\Expendable\Http\Controllers\Admin\Base\BaseComponent
生成的状态,则会从该状态生成控制器继承。此控制器实现了所有状态接口。
use Distilleries\DatatableBuilder\Contracts\DatatableStateContract; use Distilleries\Expendable\Contracts\ExportStateContract; use Distilleries\Expendable\Contracts\ImportStateContract; use Distilleries\Expendable\States\DatatableStateTrait; use Distilleries\Expendable\States\ExportStateTrait; use Distilleries\Expendable\States\FormStateTrait; use Distilleries\Expendable\States\ImportStateTrait; use Distilleries\FormBuilder\Contracts\FormStateContract; class BaseComponent extends ModelBaseController implements FormStateContract, DatatableStateContract, ExportStateContract, ImportStateContract { use FormStateTrait; use ExportStateTrait; use DatatableStateTrait; use ImportStateTrait; // ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------ public function getIndex() { return $this->getIndexDatatable(); } }
Admin ModelBaseController
如果您不想使用所有状态,并且使用一个模型,只需扩展 Distilleries\Expendable\Http\Controllers\Admin\Base\ModelBaseController
。
示例
use Distilleries\Expendable\Contracts\LayoutManagerContract; use Distilleries\Expendable\Models\BaseModel; use Illuminate\Http\Request; class ModelBaseController extends BaseController { /** * @var \Distilleries\Expendable\Models\BaseModel $model * Injected by the constructor */ protected $model; // ------------------------------------------------------------------------------------------------ public function __construct(BaseModel $model, LayoutManagerContract $layoutManager) { parent::__construct($layoutManager); $this->model = $model; } // ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------ public function putDestroy(Request $request) { $validation = \Validator::make($request->all(), [ 'id' => 'required' ]); if ($validation->fails()) { return redirect()->back()->withErrors($validation)->withInput($request->all()); } $data = $this->model->find($request->get('id')); $data->delete(); return redirect()->to(action('\\'.get_class($this) . '@getIndex')); } }
Admin BaseController
如果您不想使用所有状态并且不使用模型,只需扩展 Distilleries\Expendable\Http\Controllers\Admin\Base\BaseController
。您只需注入 LayoutManagerContract
示例
use Distilleries\Expendable\Contracts\LayoutManagerContract; use Distilleries\Expendable\Http\Controllers\Controller; class BaseController extends Controller { protected $layoutManager; protected $layout = 'expendable::admin.layout.default'; // ------------------------------------------------------------------------------------------------ public function __construct(LayoutManagerContract $layoutManager) { $this->layoutManager = $layoutManager; $this->setupLayout(); } // ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------ protected function setupLayout() { $this->layoutManager->setupLayout($this->layout); $this->setupStateProvider(); $this->initStaticPart(); } // ------------------------------------------------------------------------------------------------ protected function setupStateProvider() { $interfaces = class_implements($this); $this->layoutManager->initInterfaces($interfaces, get_class($this)); } // ------------------------------------------------------------------------------------------------ protected function initStaticPart() { $this->layoutManager->initStaticPart(function ($layoutManager) { $menu_top = $layoutManager->getView()->make('expendable::admin.menu.top'); $menu_left = $layoutManager->getView()->make('expendable::admin.menu.left'); $layoutManager->add([ 'state.menu' => $layoutManager->getState()->getRenderStateMenu(), 'menu_top' => $menu_top, 'menu_left' => $menu_left ]); }); } }
模型
默认情况下,您可以扩展 \Distilleries\Expendable\Models\BaseModel
,该模型扩展了 \Illuminate\Database\Eloquent\Model
。在其上,您可以使用一些方法
public static function getChoice(); public function scopeSearch($query, $searchQuery); public function getAllColumnsNames(); public function scopeBetweenCreate($query, $start, $end); public function scopeBetweenupdate($query, $start, $end);
全局作用域
我提供了一些可在模型上使用的全局作用域。
状态
如果您只想在连接时显示一个元素,请使用此作用域。模型检查用户是否未连接,并且状态等于在线(1)。
要使用它,请将特性添加到您的模型中 use \Distilleries\Expendable\Models\StatusTrait;
权限
权限系统基于您所有控制器中的公共方法。要生成所有服务的列表,请使用“同步所有服务”(/admin/service/synchronize
)。它使用所有控制器并获取公共操作。
如果您转到“关联权限”,您将看到具有所有方法的控制器列表
在此页面上,您可以允许角色对方法。默认情况下,Expendable 使用 Distilleries\PermissionUtil
包并在其内核中添加正确的中间件。您无需进行配置。如果未允许角色,应用程序将抛出错误 403
if(!PermissionUtil::hasAccess('Controller@action')){ App::abort(403, Lang::get('expendable::errors.unthorized')); }
视图
要覆盖视图,请使用命令行发布它们
php artisan vendor:publish --provider="Distilleries\Expendable\ExpendableServiceProvider" --tag="views"
资产(CSS和JavaScript)
所有资产都在 resources/assets
文件夹中。
Sass
要使用 sass 文件,只需在您的 admin 文件 scss 中添加 bootstrap 和 application.admin.scss
。如果您查看 Xyz 存储库,您将有一个名为 assets 的文件夹。我使用了相同的结构。
// // Third-parties // @import "../../../../node_modules/bootstrap-sass/assets/stylesheets/bootstrap"; @import "../../../../node_modules/font-awesome/scss/font-awesome"; // // Expendable // @import "../../../../vendor/distilleries/expendable/src/resources/assets/backend/sass/application.admin"; @import "../../../../vendor/distilleries/expendable/src/resources/assets/backend/sass/admin/layout/themes/grey";
图片
当它们在 sass 文件中发现时,图像将由 mix 脚本复制
JavaScript
JavaScript 由 mix 编译
Composer
我在更新我的库时,更新了我的 composer json 以添加 npm 安装和 gulp 生成
"post-update-cmd": [ "php artisan clear-compiled", "php artisan optimize", "php artisan down", "npm install", "php artisan migrate --force", "npm run production", "php artisan up" ],
创建新的后端模块
- 生成迁移
- 生成模型
- 生成组件
- 在路由文件中添加您的控制器
案例研究
尝试创建一个博客文章组件。我使用的是 Xyz 的新安装
1. 生成迁移
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreatePostsTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('posts', function(Blueprint $table) { $table->increments('id'); $table->string('libelle'); $table->text('content')->nullable(); $table->tinyInteger('status'); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::drop('posts'); } }
php artisan migrate
2. 生成模型
use Distilleries\Expendable\Models\BaseModel; class Post extends BaseModel { use \Distilleries\Expendable\Models\StatusTrait; protected $fillable = [ 'id', 'libelle', 'content', 'status', ]; }
3 生成组件
我使用后端生成器 /admin/component/edit
。
数据表
<?php namespace App\Datatables; use Distilleries\DatatableBuilder\EloquentDatatable; class PostDatatable extends EloquentDatatable { public function build() { $this ->add('id',null,trans('datatable.id')) ->add('libelle',null,trans('datatable.libelle')); $this->addDefaultAction(); } }
表单
此文件是生成的
<?php namespace App\Forms; use Distilleries\FormBuilder\FormValidator; class PostForm extends FormValidator { public static $rules = []; public static $rules_update = null; public function buildForm() { $this ->add('id', 'hidden') ->add('libelle', 'text') ->add('content', 'tinymce') ->add('status', 'choice'); $this->addDefaultActions(); } }
您必须更新它以给出选择值和验证规则
<?php namespace App\Forms; use Distilleries\Expendable\Helpers\StaticLabel; use Distilleries\FormBuilder\FormValidator; class PostForm extends FormValidator { public static $rules = [ 'libelle' => 'required', 'status' => 'required|integer' ]; public static $rules_update = null; public function buildForm() { $this ->add('id', 'hidden') ->add('libelle', 'text') ->add('status', 'choice', [ 'choices' => StaticLabel::status(), 'empty_value' => '-', 'validation' => 'required', 'label' => 'Status' ]); $this->addDefaultActions(); } }
控制器
<?php namespace App\Http\Controllers\Admin; use Distilleries\Expendable\Contracts\LayoutManagerContract; use Distilleries\Expendable\Http\Controllers\Admin\Base\BaseComponent; use App\Forms\PostForm; use App\Datatables\PostDatatable; class PostController extends BaseComponent { // ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------ public function __construct(PostDatatable $datatable, PostForm $form, \App\Post $model, LayoutManagerContract $layoutManager) { parent::__construct($model, $layoutManager); $this->datatable = $datatable; $this->form = $form; } }
4 在路由文件中添加您的控制器
我在路由文件中添加了 Route::controller('post', 'Admin\PostController');
<?php use \Route; Route::get('/', 'HomeController@index'); Route::group(array('middleware' => 'auth'), function () { Route::group(array('before' => 'permission', 'prefix' => config('expendable::admin_base_uri')), function () { Route::controller('post', 'Admin\PostController'); }); });
5 添加到菜单
在 config/expendable.php
中,id 添加 Post 条目
'menu' => \Distilleries\Expendable\Config\MenuConfig::menu([ 'left' => [ [ 'icon' => 'pushpin', 'action' => 'Admin\PostController@getIndex', 'libelle' => 'Post', 'submenu' => [ [ 'icon' => 'th-list', 'libelle' => 'List of Post', 'action' => 'Admin\PostController@getIndex', ], [ 'icon' => 'pencil', 'libelle' => 'Add Post', 'action' => 'Admin\PostController@getEdit', ] ] ], ] ], 'beginning'),