markofly / admincrud
Admin crud 生成器
v0.0.3-alpha
2016-12-19 19:44 UTC
Requires
- php: >=5.5.0
- illuminate/database: >= 5.0
- illuminate/http: >= 5.0
- illuminate/support: >= 5.0
This package is not auto-updated.
Last update: 2024-09-28 19:45:33 UTC
README
AdminCrud 是 Laravel 5 包。
安装
使用 composer
$ composer require markofly/admincrud "v0.0.3-alpha"
将服务提供者添加到 config/app.php
'providers' => [ ... Markofly\AdminCrud\AdminCrudServiceProvider::class, ],
发布配置、视图和表单文件
$ php artisan vendor:publish --provider="Markofly\AdminCrud\AdminCrudServiceProvider"
使用方法
设置 Admin crud 配置
AdminCrud 配置文件位于 config/markofly/admincrud.php
默认配置如下所示
<?php return [ 'path' => base_path('config/markofly/forms/'), ];
创建表单配置文件
默认表单配置文件位于 config/markofly/forms/
<?php return [ 'model' => App\User::class, // Model class for forms 'route_name' => 'users', // Resource route prefix 'per_page' => 5, // Per page number for list view 'create_form' => [...], // Create form fields 'edit_form' => [...], // Edit form fields 'list' => [...], // List view fields ];
创建表单字段
[
'label' => 'Password', // Label for fields
'type' => 'password', // Field type Currently available: text, password, textarea, checkbox, checkboxes, radio, select
'multiple_data' => [ // Used only for radio, checkboxes, select
[
'label' => 'First label',
'value' => 'first',
],
],
'name' => 'password', // Field name
'database_field' => 'password', // false for non database field; Database field name
'validation_rules' => 'required|min:6|confirmed', //Laravel validation rules
'storing_method' => function($value) { return bcrypt($value); }, // null for storing same value; function for storing custom value
],
编辑表单字段
[
'label' => 'Full name', // Label for fields
'type' => 'text', // Field type Currently available: text, password, textarea, checkbox, checkboxes, radio, select
'multiple_data' => [ // Used only for radio, checkboxes, select
[
'label' => 'First label',
'value' => 'first',
],
],
'name' => 'name', // Field name
'database_field' => 'name', // false for non database field; Database field name
'validation_rules' => 'required', //Laravel validation rules
'storing_method' => null, // null for storing same value; function for storing custom value
'editable' => true // Is field disabled or not; Default value is true
],
列表视图字段
[
'label' => 'Full name', // Field label
'database_field' => 'name', // Database field name
],
为表单创建控制器
$ php artisan make:controller UsersController
基本的 AdminCrud 控制器应该看起来像这样
<?php namespace App\Http\Controllers; use Markofly\AdminCrud\AdminCrud; use Markofly\AdminCrud\AdminCrudTrait; class UsersController extends Controller { use AdminCrudTrait; public function initializeAdminCrud() { $this->adminCrud = new AdminCrud('users'); $this->pageTitle = 'Users'; } }
为控制器注册新路由
Route::resource('users', 'UsersController');
更改默认布局文件
默认视图文件位于 resources/views/vendor/AdminCrud/default.blade.php
许可证
MIT 许可证 (MIT)。请参阅 许可证文件 了解更多信息。