Showing
6 changed files
with
103 additions
and
25 deletions
| ... | @@ -6,6 +6,7 @@ use App\Admin\Renderable\VerseTable; | ... | @@ -6,6 +6,7 @@ use App\Admin\Renderable\VerseTable; |
| 6 | use App\Admin\Repositories\OnePoem; | 6 | use App\Admin\Repositories\OnePoem; |
| 7 | use App\Admin\Repositories\Verse; | 7 | use App\Admin\Repositories\Verse; |
| 8 | use App\Models\Author; | 8 | use App\Models\Author; |
| 9 | +use App\Models\OnePoem2; | ||
| 9 | use App\Models\Poetry; | 10 | use App\Models\Poetry; |
| 10 | use Dcat\Admin\Form; | 11 | use Dcat\Admin\Form; |
| 11 | use Dcat\Admin\Grid; | 12 | use Dcat\Admin\Grid; |
| ... | @@ -25,13 +26,31 @@ class OnePoemController extends AdminController | ... | @@ -25,13 +26,31 @@ class OnePoemController extends AdminController |
| 25 | */ | 26 | */ |
| 26 | protected function grid() | 27 | protected function grid() |
| 27 | { | 28 | { |
| 28 | - return Grid::make(new OnePoem(), function (Grid $grid) { | 29 | +// return Grid::make(new OnePoem(), function (Grid $grid) { |
| 30 | +// $grid->column('id')->sortable(); | ||
| 31 | +// $grid->column('title'); | ||
| 32 | +// $grid->column('content'); | ||
| 33 | +// $grid->column('annotate'); | ||
| 34 | +// $grid->column('spelling'); | ||
| 35 | +// $grid->column('en'); | ||
| 36 | +// $grid->column('created_at'); | ||
| 37 | +// $grid->column('updated_at')->sortable(); | ||
| 38 | +// | ||
| 39 | +// $grid->filter(function (Grid\Filter $filter) { | ||
| 40 | +// $filter->equal('id'); | ||
| 41 | +// }); | ||
| 42 | +// }); | ||
| 43 | + | ||
| 44 | + return Grid::make(new OnePoem2(), function (Grid $grid) { | ||
| 45 | + $grid->model()->with('verses'); | ||
| 29 | $grid->column('id')->sortable(); | 46 | $grid->column('id')->sortable(); |
| 30 | $grid->column('title'); | 47 | $grid->column('title'); |
| 31 | - $grid->column('content'); | 48 | + $grid->column('author'); |
| 32 | - $grid->column('annotate'); | 49 | +// $grid->column('content'); |
| 33 | - $grid->column('spelling'); | 50 | + $grid->verses('正文')->pluck('stanza')->label(); |
| 34 | - $grid->column('en'); | 51 | +// $grid->column('annotate'); |
| 52 | +// $grid->column('spelling'); | ||
| 53 | +// $grid->column('en'); | ||
| 35 | $grid->column('created_at'); | 54 | $grid->column('created_at'); |
| 36 | $grid->column('updated_at')->sortable(); | 55 | $grid->column('updated_at')->sortable(); |
| 37 | 56 | ||
| ... | @@ -87,21 +106,13 @@ class OnePoemController extends AdminController | ... | @@ -87,21 +106,13 @@ class OnePoemController extends AdminController |
| 87 | $form->text('title'); | 106 | $form->text('title'); |
| 88 | $form->text('author'); | 107 | $form->text('author'); |
| 89 | 108 | ||
| 90 | - $form->hasMany('components','诗句组', function (Form\NestedForm $form) { | 109 | + $form->hasMany('verses','诗句组', function (Form\NestedForm $form) { |
| 91 | - | 110 | + $form->selectTable('verse_id','诗句') |
| 92 | - $form->selectTable('font_file','诗句') | ||
| 93 | ->title('字体选择') | 111 | ->title('字体选择') |
| 94 | ->from(VerseTable::make()) | 112 | ->from(VerseTable::make()) |
| 95 | ->model(\App\Models\Verse::class,'id','stanza'); | 113 | ->model(\App\Models\Verse::class,'id','stanza'); |
| 96 | - | ||
| 97 | - | ||
| 98 | }); | 114 | }); |
| 99 | 115 | ||
| 100 | -// $form->textarea('content'); | ||
| 101 | -// $form->text('annotate'); | ||
| 102 | -// $form->text('spelling'); | ||
| 103 | -// $form->text('en'); | ||
| 104 | - | ||
| 105 | $form->display('created_at'); | 116 | $form->display('created_at'); |
| 106 | $form->display('updated_at'); | 117 | $form->display('updated_at'); |
| 107 | }); | 118 | }); |
| ... | @@ -109,8 +120,21 @@ class OnePoemController extends AdminController | ... | @@ -109,8 +120,21 @@ class OnePoemController extends AdminController |
| 109 | 120 | ||
| 110 | public function store() | 121 | public function store() |
| 111 | { | 122 | { |
| 112 | - return request()->all(); | 123 | + // 写 一言表 |
| 113 | -// return $this->form()->store(); | 124 | + $post = request()->all(); |
| 125 | + $poem2 = OnePoem2::query()->create([ | ||
| 126 | + 'title' => $post['title'], | ||
| 127 | + 'author' => $post['author'], | ||
| 128 | + ]); | ||
| 129 | + | ||
| 130 | + // 写关联表 | ||
| 131 | + $verse_ids = []; | ||
| 132 | + foreach ($post['verses'] as $verse){ | ||
| 133 | + $verse_ids[] = $verse['verse_id']; | ||
| 134 | + } | ||
| 135 | + $poem2->verses()->sync($verse_ids); | ||
| 136 | + | ||
| 137 | + return $this->form()->response()->success('添加成功'); | ||
| 114 | } | 138 | } |
| 115 | 139 | ||
| 116 | protected function PoetryGrid() | 140 | protected function PoetryGrid() | ... | ... |
| ... | @@ -2,6 +2,7 @@ | ... | @@ -2,6 +2,7 @@ |
| 2 | 2 | ||
| 3 | namespace App\Admin\Controllers; | 3 | namespace App\Admin\Controllers; |
| 4 | 4 | ||
| 5 | +use App\Admin\Renderable\AuthorTable; | ||
| 5 | use App\Admin\Repositories\Poetry; | 6 | use App\Admin\Repositories\Poetry; |
| 6 | use Dcat\Admin\Form; | 7 | use Dcat\Admin\Form; |
| 7 | use Dcat\Admin\Grid; | 8 | use Dcat\Admin\Grid; |
| ... | @@ -19,11 +20,14 @@ class PoetryController extends AdminController | ... | @@ -19,11 +20,14 @@ class PoetryController extends AdminController |
| 19 | protected function grid() | 20 | protected function grid() |
| 20 | { | 21 | { |
| 21 | return Grid::make(new Poetry(), function (Grid $grid) { | 22 | return Grid::make(new Poetry(), function (Grid $grid) { |
| 23 | + $grid->model()->with(['author']); | ||
| 22 | $grid->column('id')->sortable(); | 24 | $grid->column('id')->sortable(); |
| 25 | + $grid->column('author.name','作者'); | ||
| 23 | $grid->column('name'); | 26 | $grid->column('name'); |
| 24 | $grid->column('subname'); | 27 | $grid->column('subname'); |
| 25 | $grid->column('alias'); | 28 | $grid->column('alias'); |
| 26 | $grid->column('en'); | 29 | $grid->column('en'); |
| 30 | + $grid->column('state','状态')->switch(); | ||
| 27 | $grid->column('created_at'); | 31 | $grid->column('created_at'); |
| 28 | $grid->column('updated_at')->sortable(); | 32 | $grid->column('updated_at')->sortable(); |
| 29 | 33 | ||
| ... | @@ -62,7 +66,12 @@ class PoetryController extends AdminController | ... | @@ -62,7 +66,12 @@ class PoetryController extends AdminController |
| 62 | protected function form() | 66 | protected function form() |
| 63 | { | 67 | { |
| 64 | return Form::make(new Poetry(), function (Form $form) { | 68 | return Form::make(new Poetry(), function (Form $form) { |
| 69 | + | ||
| 65 | $form->display('id'); | 70 | $form->display('id'); |
| 71 | + $form->selectTable('author_id','作者') | ||
| 72 | + ->title('字体选择') | ||
| 73 | + ->from(AuthorTable::make()) | ||
| 74 | + ->model(\App\Models\Author::class,'id','name'); | ||
| 66 | $form->text('name'); | 75 | $form->text('name'); |
| 67 | $form->text('subname'); | 76 | $form->text('subname'); |
| 68 | $form->text('alias'); | 77 | $form->text('alias'); | ... | ... |
app/Admin/Renderable/AuthorTable.php
0 → 100644
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * Created by PhpStorm. | ||
| 4 | + * User: lishuai | ||
| 5 | + * Date: 2022/1/10 | ||
| 6 | + * Time: 5:57 PM | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | +namespace App\Admin\Renderable; | ||
| 10 | + | ||
| 11 | +use App\Admin\Repositories\OnePoem; | ||
| 12 | +use App\Models\Author; | ||
| 13 | +use Dcat\Admin\Grid; | ||
| 14 | +use Dcat\Admin\Grid\LazyRenderable; | ||
| 15 | + | ||
| 16 | +class AuthorTable extends LazyRenderable | ||
| 17 | +{ | ||
| 18 | + public function grid(): Grid | ||
| 19 | + { | ||
| 20 | + return Grid::make(new Author(), function (Grid $grid) { | ||
| 21 | + $grid->column('id', 'ID')->sortable(); | ||
| 22 | + $grid->column('name'); | ||
| 23 | + $grid->column('dynasty'); | ||
| 24 | + $grid->column('introduce'); | ||
| 25 | + $grid->column('state')->switch(); | ||
| 26 | + | ||
| 27 | + $grid->quickSearch(['name', 'dynasty', 'introduce']); | ||
| 28 | + | ||
| 29 | + $grid->paginate(10); | ||
| 30 | + $grid->disableActions(); | ||
| 31 | + | ||
| 32 | + $grid->filter(function (Grid\Filter $filter) { | ||
| 33 | + $filter->like('name')->width(3); | ||
| 34 | + $filter->like('dynasty')->width(3); | ||
| 35 | + $filter->like('introduce')->width(3); | ||
| 36 | + }); | ||
| 37 | + }); | ||
| 38 | + } | ||
| 39 | +} | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| ... | @@ -23,13 +23,13 @@ class VerseTable extends LazyRenderable | ... | @@ -23,13 +23,13 @@ class VerseTable extends LazyRenderable |
| 23 | $grid->model()->with(['poetry']); | 23 | $grid->model()->with(['poetry']); |
| 24 | 24 | ||
| 25 | $grid->column('id')->sortable(); | 25 | $grid->column('id')->sortable(); |
| 26 | - $grid->column('author_id')->display(function (){ | 26 | +// $grid->column('author_id')->display(function (){ |
| 27 | - $id = $this->poetry_id; | 27 | +// $id = $this->poetry_id; |
| 28 | - $poetry = Poetry::query()->find($id); | 28 | +// $poetry = Poetry::query()->find($id); |
| 29 | - $author_id = $poetry->author_id; | 29 | +// $author_id = $poetry->author_id; |
| 30 | - $author = Author::query()->find($author_id); | 30 | +// $author = Author::query()->find($author_id); |
| 31 | - return $author->name; | 31 | +// return $author->name; |
| 32 | - })->copyable(); | 32 | +// })->copyable(); |
| 33 | $grid->column('poetry.name')->copyable(); | 33 | $grid->column('poetry.name')->copyable(); |
| 34 | 34 | ||
| 35 | $grid->column('stanza')->copyable(); | 35 | $grid->column('stanza')->copyable(); | ... | ... |
| ... | @@ -11,9 +11,15 @@ class OnePoem2 extends Model | ... | @@ -11,9 +11,15 @@ class OnePoem2 extends Model |
| 11 | use HasDateTimeFormatter; | 11 | use HasDateTimeFormatter; |
| 12 | protected $table = 'one_poem2'; | 12 | protected $table = 'one_poem2'; |
| 13 | 13 | ||
| 14 | + protected $fillable = ['title','author']; | ||
| 14 | 15 | ||
| 15 | public function admin_make_video() | 16 | public function admin_make_video() |
| 16 | { | 17 | { |
| 17 | return $this->belongsTo(AdminMakeVideo::class,'poem_id'); | 18 | return $this->belongsTo(AdminMakeVideo::class,'poem_id'); |
| 18 | } | 19 | } |
| 20 | + | ||
| 21 | + public function verses() | ||
| 22 | + { | ||
| 23 | + return $this->belongsToMany(Verse::class, 'verse_poem2', 'poem_id', 'verse_id'); | ||
| 24 | + } | ||
| 19 | } | 25 | } | ... | ... |
| ... | @@ -4,7 +4,7 @@ use Illuminate\Database\Migrations\Migration; | ... | @@ -4,7 +4,7 @@ use Illuminate\Database\Migrations\Migration; |
| 4 | use Illuminate\Database\Schema\Blueprint; | 4 | use Illuminate\Database\Schema\Blueprint; |
| 5 | use Illuminate\Support\Facades\Schema; | 5 | use Illuminate\Support\Facades\Schema; |
| 6 | 6 | ||
| 7 | -class CreateOnePoem2Table extends Migration | 7 | +class CreateVerseOnePoem2Table extends Migration |
| 8 | { | 8 | { |
| 9 | /** | 9 | /** |
| 10 | * Run the migrations. | 10 | * Run the migrations. | ... | ... |
-
Please register or login to post a comment