配置管理
parent
bea4d94338
commit
912640dfde
|
|
@ -0,0 +1,7 @@
|
|||
.DS_Store
|
||||
phpunit.phar
|
||||
/vendor
|
||||
composer.phar
|
||||
composer.lock
|
||||
*.project
|
||||
.idea/
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# Dcat Admin Extension
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
{
|
||||
"name": "peidikeji/setting",
|
||||
"alias": "setting",
|
||||
"description": "Setting",
|
||||
"type": "library",
|
||||
"keywords": ["dcat-admin", "extension"],
|
||||
"homepage": "https://github.com/peidikeji/setting",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "panliang",
|
||||
"email": "1163816051@qq.com"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.1.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Peidikeji\\Setting\\": "src/"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
"dcat-admin": "Peidikeji\\Setting\\SettingServiceProvider",
|
||||
"laravel": {
|
||||
"providers": [
|
||||
"Peidikeji\\Setting\\SettingServiceProvider"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'labels' => [
|
||||
'Setting' => '配置管理',
|
||||
'setting' => '配置管理',
|
||||
],
|
||||
'fields' => [
|
||||
'slug' => 'key',
|
||||
'value' => 'value',
|
||||
],
|
||||
'options' => [
|
||||
],
|
||||
];
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'labels' => [
|
||||
'Setting' => '配置管理',
|
||||
'setting' => '配置管理',
|
||||
],
|
||||
'fields' => [
|
||||
'slug' => 'key',
|
||||
'value' => 'value',
|
||||
],
|
||||
'options' => [
|
||||
],
|
||||
];
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
namespace Peidikeji\Setting\Http\Controllers;
|
||||
|
||||
use Dcat\Admin\Form;
|
||||
use Dcat\Admin\Grid;
|
||||
use Dcat\Admin\Http\Controllers\AdminController;
|
||||
use Peidikeji\Setting\Models\Setting;
|
||||
use Dcat\Admin\Show;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class SettingController extends AdminController
|
||||
{
|
||||
protected $translation = 'peidikeji.dcat-admin-extension-setting::setting';
|
||||
|
||||
protected function grid()
|
||||
{
|
||||
return Grid::make(new Setting(), function (Grid $grid) {
|
||||
$grid->column('slug');
|
||||
$grid->column('name');
|
||||
$grid->column('value');
|
||||
|
||||
$grid->showCreateButton();
|
||||
$grid->showQuickEditButton();
|
||||
$grid->showDeleteButton();
|
||||
$grid->showViewButton();
|
||||
|
||||
$grid->quickSearch(['slug', 'name', 'value'])->placeholder('输入 key/名称/value 搜索');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a show builder.
|
||||
*
|
||||
* @param mixed $id
|
||||
*
|
||||
* @return Show
|
||||
*/
|
||||
protected function detail($id)
|
||||
{
|
||||
return Show::make($id, new Setting(), function (Show $show) {
|
||||
$show->field('slug');
|
||||
$show->field('name');
|
||||
$show->field('value');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Make a form builder.
|
||||
*
|
||||
* @return Form
|
||||
*/
|
||||
protected function form()
|
||||
{
|
||||
return Form::make(new Setting(), function (Form $form) {
|
||||
$unique = Rule::unique((new Setting())->getTable(), 'slug');
|
||||
if ($form->isEditing()) {
|
||||
$unique->ignore($form->getKey(), 'slug');
|
||||
}
|
||||
$form->text('name')->required();
|
||||
$form->text('slug')->required()->help('不能重复')->rules([$unique]);
|
||||
$form->textarea('value')->required();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Peidikeji\Setting\Http\Controllers;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::resource('setting', SettingController::class)->names('setting');
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Peidikeji\Setting\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Setting extends Model
|
||||
{
|
||||
protected $primaryKey = 'slug';
|
||||
|
||||
public $incrementing = false;
|
||||
|
||||
protected $fillable = ['slug', 'value', 'name'];
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Peidikeji\Setting;
|
||||
|
||||
use Dcat\Admin\Extend\Setting as Form;
|
||||
|
||||
class Setting extends Form
|
||||
{
|
||||
public function form()
|
||||
{
|
||||
$this->text('key1')->required();
|
||||
$this->text('key2')->required();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
namespace Peidikeji\Setting;
|
||||
|
||||
use Dcat\Admin\Extend\ServiceProvider;
|
||||
use Dcat\Admin\Admin;
|
||||
|
||||
class SettingServiceProvider extends ServiceProvider
|
||||
{
|
||||
protected $menu = [
|
||||
['title' => 'Setting', 'uri' => 'keywords', 'icon' => ''],
|
||||
];
|
||||
|
||||
public function register()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
//
|
||||
|
||||
}
|
||||
|
||||
// public function settingForm()
|
||||
// {
|
||||
// return new Setting($this);
|
||||
// }
|
||||
}
|
||||
|
|
@ -6,16 +6,6 @@ use Illuminate\Support\Facades\Schema;
|
|||
|
||||
class CreateAdminSettingsTable extends Migration
|
||||
{
|
||||
public function getConnection()
|
||||
{
|
||||
return $this->config('database.connection') ?: config('database.default');
|
||||
}
|
||||
|
||||
public function config($key)
|
||||
{
|
||||
return config('admin.'.$key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
|
|
@ -23,10 +13,13 @@ class CreateAdminSettingsTable extends Migration
|
|||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create($this->config('database.settings_table') ?: 'admin_settings', function (Blueprint $table) {
|
||||
Schema::create('admin_settings', function (Blueprint $table) {
|
||||
$table->string('slug', 100)->primary();
|
||||
$table->longText('value');
|
||||
$table->string('name')->nullable();
|
||||
$table->timestamps();
|
||||
|
||||
$table->comment('配置表');
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -37,6 +30,6 @@ class CreateAdminSettingsTable extends Migration
|
|||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists($this->config('database.settings_table') ?: 'admin_settings');
|
||||
Schema::dropIfExists('admin_settings');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'1.0.0' => [
|
||||
'Initialize extension.',
|
||||
],
|
||||
];
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Dcat\Admin\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Setting extends Model
|
||||
{
|
||||
protected $primaryKey = 'slug';
|
||||
public $incrementing = false;
|
||||
protected $fillable = ['slug', 'value'];
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function __construct(array $attributes = [])
|
||||
{
|
||||
$this->init();
|
||||
|
||||
parent::__construct($attributes);
|
||||
}
|
||||
|
||||
protected function init()
|
||||
{
|
||||
$connection = config('admin.database.connection') ?: config('database.default');
|
||||
|
||||
$this->setConnection($connection);
|
||||
|
||||
$this->setTable(config('admin.database.settings_table') ?: 'admin_settings');
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue