|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Encore\Admin\Config; |
| 4 | + |
| 5 | +use Encore\Admin\Controllers\ModelForm; |
| 6 | +use Encore\Admin\Facades\Admin; |
| 7 | +use Encore\Admin\Form; |
| 8 | +use Encore\Admin\Grid; |
| 9 | +use Encore\Admin\Layout\Content; |
| 10 | + |
| 11 | +class ConfigController |
| 12 | +{ |
| 13 | + use ModelForm; |
| 14 | + |
| 15 | + /** |
| 16 | + * Index interface. |
| 17 | + * |
| 18 | + * @return Content |
| 19 | + */ |
| 20 | + public function index() |
| 21 | + { |
| 22 | + return Admin::content(function (Content $content) { |
| 23 | + $content->header('Config'); |
| 24 | + $content->description('Config list..'); |
| 25 | + |
| 26 | + $content->body($this->grid()); |
| 27 | + }); |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * Edit interface. |
| 32 | + * |
| 33 | + * @param $id |
| 34 | + * |
| 35 | + * @return Content |
| 36 | + */ |
| 37 | + public function edit($id) |
| 38 | + { |
| 39 | + return Admin::content(function (Content $content) use ($id) { |
| 40 | + $content->header('header'); |
| 41 | + $content->description('description'); |
| 42 | + |
| 43 | + $content->body($this->form()->edit($id)); |
| 44 | + }); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * Create interface. |
| 49 | + * |
| 50 | + * @return Content |
| 51 | + */ |
| 52 | + public function create() |
| 53 | + { |
| 54 | + return Admin::content(function (Content $content) { |
| 55 | + $content->header('header'); |
| 56 | + $content->description('description'); |
| 57 | + |
| 58 | + $content->body($this->form()); |
| 59 | + }); |
| 60 | + } |
| 61 | + |
| 62 | + public function grid() |
| 63 | + { |
| 64 | + return Admin::grid(ConfigModel::class, function (Grid $grid) { |
| 65 | + $grid->id('ID')->sortable(); |
| 66 | + $grid->name()->display(function ($name) { |
| 67 | + return "<a tabindex=\"0\" class=\"btn btn-xs btn-twitter\" role=\"button\" data-toggle=\"popover\" data-html=true title=\"Usage\" data-content=\"<code>config('$name');</code>\">$name</a>"; |
| 68 | + }); |
| 69 | + $grid->value(); |
| 70 | + $grid->description(); |
| 71 | + |
| 72 | + $grid->created_at(); |
| 73 | + $grid->updated_at(); |
| 74 | + |
| 75 | + $grid->filter(function ($filter) { |
| 76 | + $filter->disableIdFilter(); |
| 77 | + $filter->like('name'); |
| 78 | + $filter->like('value'); |
| 79 | + }); |
| 80 | + }); |
| 81 | + } |
| 82 | + |
| 83 | + public function form() |
| 84 | + { |
| 85 | + return Admin::form(ConfigModel::class, function (Form $form) { |
| 86 | + $form->display('id', 'ID'); |
| 87 | + $form->text('name')->rules('required'); |
| 88 | + $form->textarea('value')->rules('required'); |
| 89 | + $form->textarea('description'); |
| 90 | + |
| 91 | + $form->display('created_at'); |
| 92 | + $form->display('updated_at'); |
| 93 | + }); |
| 94 | + } |
| 95 | +} |
0 commit comments