OnePoemController.php
5.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
namespace App\Admin\Controllers;
use App\Admin\Repositories\Verse;
use App\Models\Author;
use App\Models\OnePoem2;
use App\Models\Poetry;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Widgets\Card;
use Dcat\Admin\Widgets\Table;
class OnePoemController extends AdminController
{
protected $title = '一言';
/**
* Make a grid builder.
*
* @return Grid
*/
protected function grid()
{
// return Grid::make(new OnePoem(), function (Grid $grid) {
// $grid->column('id')->sortable();
// $grid->column('title');
// $grid->column('content');
// $grid->column('annotate');
// $grid->column('spelling');
// $grid->column('en');
// $grid->column('created_at');
// $grid->column('updated_at')->sortable();
//
// $grid->filter(function (Grid\Filter $filter) {
// $filter->equal('id');
// });
// });
return Grid::make(new OnePoem2(), function (Grid $grid) {
$grid->model()->with('verses');
$grid->column('id')->sortable();
$grid->column('title');
$grid->column('author');
$grid->column('','诗句组')
->display('展开')
->expand(function (){
$th = ['id','一言Id','正文','注释','拼音','英文','创建时间','修改时间'];
return Table::make($th, $this->verses->toArray())->withBorder();
});
$grid->column('created_at');
$grid->column('updated_at')->sortable();
$grid->filter(function (Grid\Filter $filter) {
$filter->equal('id');
});
});
}
/**
* Make a show builder.
*
* @param mixed $id
*
* @return Show
*/
protected function detail($id)
{
return Show::make($id, new OnePoem2(), function (Show $show) {
$show->field('id');
$show->field('title');
$show->field('content');
$show->field('annotate');
$show->field('spelling');
$show->field('en');
$show->field('poetry_id');
$show->field('created_at');
$show->field('updated_at');
});
}
public function create(Content $content)
{
return $content
->translation($this->translation())
->title($this->title())
->description('注意:基础库中内容只做参考,创建的一言与其他表数据不耦合!理论上可自行组装句子,也可按诗词原文复制。')
// ->description($this->description()['create'] ?? trans('admin.create'))
->body(Card::make($this->PoetryGrid()))
->body($this->form());
}
/**
* Make a form builder.
*
* @return Form
*/
protected function form()
{
$builder = OnePoem2::with(['verses']);
return Form::make($builder, function (Form $form) {
$form->display('id');
$form->text('title');
$form->text('author');
$form->hasMany('verses','诗句组', function (Form\NestedForm $form) {
$form->textarea('content');
$form->textarea('annotate');
$form->textarea('spelling');
$form->textarea('en');
})->useTable();
$form->display('created_at');
$form->display('updated_at');
});
}
protected function PoetryGrid()
{
return Grid::make(new Verse(), function (Grid $grid) {
$grid->model()->with(['poetry']);
$grid->column('id')->sortable();
$grid->column('author_id','作者')->display(function (){
$id = $this->poetry_id;
$poetry = Poetry::query()->find($id);
$author_id = $poetry->author_id;
$author = Author::query()->find($author_id);
return $author->name;
})->copyable();
$grid->column('poetry.name')->copyable();
$grid->column('stanza')->copyable();
$grid->column('annotate')->copyable();
$grid->column('spelling')->copyable();
$grid->column('en')->copyable();
$grid->withBorder();
$grid->quickSearch(['stanza'])->placeholder('快捷搜索诗节(支持模糊查询)');
$grid->paginate(5);
$grid->simplePaginate();
$grid->disableActions();
$grid->disableCreateButton();
$grid->filter(function (Grid\Filter $filter) {
$filter->where('author_id',function ($query){
$author = Author::query()->where('name','like',"%{$this->input}%")->get()->pluck('id');
$poetry =Poetry::query()->whereIn('author_id',$author)->get()->pluck('id');
$query->whereIn('poetry_id',$poetry);
},'作者')->width(3);
$filter->like('poetry.name')->width(3);
$filter->like('stanza')->width(4);
$filter->panel();
$filter->expand();
});
});
}
}