OnePoemController.php
4.29 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
<?php
namespace App\Admin\Controllers;
use App\Admin\Repositories\OnePoem;
use App\Admin\Repositories\Verse;
use App\Models\Author;
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;
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');
});
});
}
/**
* Make a show builder.
*
* @param mixed $id
*
* @return Show
*/
protected function detail($id)
{
return Show::make($id, new OnePoem(), 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()
{
return Form::make(new OnePoem(), function (Form $form) {
$form->display('id');
$form->text('title');
$form->text('author');
$form->textarea('content');
$form->text('annotate');
$form->text('spelling');
$form->text('en');
$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->column('created_at');
// $grid->column('updated_at')->sortable();
$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();
});
});
}
}