添加后台管理农作物
parent
8d7fa2ef1f
commit
e745df956e
|
|
@ -0,0 +1,103 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Admin\Controllers;
|
||||||
|
|
||||||
|
use App\Models\Crop;
|
||||||
|
use Dcat\Admin\Form;
|
||||||
|
use Dcat\Admin\Grid;
|
||||||
|
use Dcat\Admin\Show;
|
||||||
|
use Dcat\Admin\Admin;
|
||||||
|
use Peidikeji\Keywords\Models\Keywords;
|
||||||
|
use Dcat\Admin\Http\Controllers\AdminController;
|
||||||
|
|
||||||
|
class CropController extends AdminController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Make a grid builder.
|
||||||
|
*
|
||||||
|
* @return Grid
|
||||||
|
*/
|
||||||
|
protected function grid()
|
||||||
|
{
|
||||||
|
return Grid::make(Crop::with(['category', 'parent']), function (Grid $grid) {
|
||||||
|
$grid->column('id')->sortable();
|
||||||
|
$grid->column('category.name', '行业');
|
||||||
|
$grid->column('parent.name', '上级');
|
||||||
|
// $grid->column('crop_type');
|
||||||
|
$grid->column('name');
|
||||||
|
$grid->column('is_end')->bool();
|
||||||
|
$grid->column('unit');
|
||||||
|
$grid->column('sort');
|
||||||
|
// $grid->column('extends');
|
||||||
|
$grid->column('created_at')->sortable();
|
||||||
|
// $grid->column('updated_at')
|
||||||
|
|
||||||
|
$grid->showCreateButton(! config('admin.permission.enable') || Admin::user()->can('dcat.admin.crops.create'));
|
||||||
|
$grid->showQuickEditButton(! config('admin.permission.enable') || Admin::user()->can('dcat.admin.crops.edit'));
|
||||||
|
$grid->showDeleteButton(! config('admin.permission.enable') || Admin::user()->can('dcat.admin.crops.destroy'));
|
||||||
|
|
||||||
|
$grid->filter(function (Grid\Filter $filter) {
|
||||||
|
$filter->like('name')->width(3);
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make a show builder.
|
||||||
|
*
|
||||||
|
* @param mixed $id
|
||||||
|
*
|
||||||
|
* @return Show
|
||||||
|
*/
|
||||||
|
protected function detail($id)
|
||||||
|
{
|
||||||
|
return Show::make($id, new Crop(), function (Show $show) {
|
||||||
|
$show->field('id');
|
||||||
|
$show->field('category_id');
|
||||||
|
$show->field('parent_id');
|
||||||
|
$show->field('crop_type');
|
||||||
|
$show->field('name');
|
||||||
|
$show->field('is_end');
|
||||||
|
$show->field('unit');
|
||||||
|
$show->field('sort');
|
||||||
|
$show->field('extends');
|
||||||
|
$show->field('created_at');
|
||||||
|
$show->field('updated_at');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make a form builder.
|
||||||
|
*
|
||||||
|
* @return Form
|
||||||
|
*/
|
||||||
|
protected function form()
|
||||||
|
{
|
||||||
|
return Form::make(new Crop(), function (Form $form) {
|
||||||
|
$form->display('id');
|
||||||
|
$form->select('category_id')->options(Keywords::where('type_key', 'crops-category')->get()->pluck('name', 'id'));
|
||||||
|
$form->select('parent_id')->options(Crop::selectOptions(function($q){
|
||||||
|
return $q->where('is_end', 0);
|
||||||
|
}))->required();
|
||||||
|
// $form->text('parent_id');
|
||||||
|
$form->radio('crop_type')->options([
|
||||||
|
1=> '基地',
|
||||||
|
2=> '镇街'
|
||||||
|
])->default(2);
|
||||||
|
$form->text('name');
|
||||||
|
$form->switch('is_end');
|
||||||
|
$form->text('unit');
|
||||||
|
$form->number('sort');
|
||||||
|
$form->table('extends', function ($table) {
|
||||||
|
$table->text('name', '类目');
|
||||||
|
$table->text('unit', '单位');
|
||||||
|
})->saving(function ($v) {
|
||||||
|
return json_encode($v);
|
||||||
|
});
|
||||||
|
|
||||||
|
$form->display('created_at');
|
||||||
|
$form->display('updated_at');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -16,4 +16,6 @@ Route::group([
|
||||||
$router->resource('friend-links', 'FriendLinkController')->names('friend_links');
|
$router->resource('friend-links', 'FriendLinkController')->names('friend_links');
|
||||||
|
|
||||||
$router->resource('agricultural-bases', 'AgriculturalBaseController')->names('agricultural_bases');
|
$router->resource('agricultural-bases', 'AgriculturalBaseController')->names('agricultural_bases');
|
||||||
|
|
||||||
|
$router->resource('crops', 'CropController')->names('crops');
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,17 @@ namespace App\Models;
|
||||||
|
|
||||||
use EloquentFilter\Filterable;
|
use EloquentFilter\Filterable;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Peidikeji\Keywords\Models\Keywords;
|
||||||
|
use Dcat\Admin\Traits\HasDateTimeFormatter;
|
||||||
|
use Dcat\Admin\Traits\ModelTree;
|
||||||
|
|
||||||
class Crop extends Model
|
class Crop extends Model
|
||||||
{
|
{
|
||||||
use Filterable;
|
use ModelTree,Filterable,HasDateTimeFormatter;
|
||||||
|
|
||||||
|
protected $titleColumn = 'name';
|
||||||
|
|
||||||
|
protected $orderColumn = 'sort';
|
||||||
|
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
'extends' => 'array'
|
'extends' => 'array'
|
||||||
|
|
@ -27,4 +34,12 @@ class Crop extends Model
|
||||||
'extends',
|
'extends',
|
||||||
'crop_type'
|
'crop_type'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public function category(){
|
||||||
|
return $this->belongsTo(Keywords::class, 'category_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function parent(){
|
||||||
|
return $this->belongsTo(self::class, 'parent_id');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -503,8 +503,7 @@ namespace Dcat\Admin {
|
||||||
class Show {}
|
class Show {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @method \Amap amap(...$params)
|
* @method \App\Admin\Form\Amap amap(...$params)
|
||||||
* @method \Region region(...$params)
|
|
||||||
*/
|
*/
|
||||||
class Form {}
|
class Form {}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
<?php
|
||||||
|
return [
|
||||||
|
'labels' => [
|
||||||
|
'Crop' => 'Crop',
|
||||||
|
'crop' => 'Crop',
|
||||||
|
],
|
||||||
|
'fields' => [
|
||||||
|
'category_id' => '行业',
|
||||||
|
'parent_id' => '父级',
|
||||||
|
'crop_type' => '类别',
|
||||||
|
'name' => '名称',
|
||||||
|
'is_end' => '是否结点',
|
||||||
|
'unit' => '单位',
|
||||||
|
'sort' => '排序',
|
||||||
|
'extends' => '扩展字段',
|
||||||
|
],
|
||||||
|
'options' => [
|
||||||
|
],
|
||||||
|
];
|
||||||
Loading…
Reference in New Issue