123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
- namespace App\Admin\Controllers;
- use App\Models\User;
- use Dcat\Admin\Form;
- use Dcat\Admin\Grid;
- use Dcat\Admin\Show;
- use Dcat\Admin\Http\Controllers\AdminController;
- class UserController extends AdminController
- {
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- return Grid::make(User::with(['info']), function (Grid $grid) {
- $grid->model()->orderByDesc('id');
- $grid->column('id')->sortable();
- $grid->column('avatar')->display(function () {
- $str = "";
- $str .= "<div style='margin-right:10px;display: flex;align-items: center'>";
- $str .= '<img data-action="preview-img" src="' . $this->avatar . '" style="height:50px;width:50px;cursor:pointer;margin-right:10px;" class="img img-thumbnail">';
- $str .= '<div>';
- $str .= '<p style="margin-bottom: 5px">' . $this->nickname . '</p>';
- $str .= '<p style="margin-bottom: 0px">' . $this->mobile . '</p>';
- $str .= "</div>";
- $str .= "</div>";
- return $str;
- });
- $grid->column('info.is_vip','是否会员')->using([0 => '否', 1 => '是'])->label(['gray', 'primary']);
- $grid->column('info.integral','金币余额');
- $grid->column('info.platform','注册平台')->using([1 => '抖音', 2 => '快手'])->label(['gray', 'primary']);;
- $grid->column('created_at','注册时间');
- $grid->filter(function (Grid\Filter $filter) {
- $filter->panel();
- $filter->equal('id','ID')->width(3);
- $filter->like('nickname')->width(3);
- $filter->equal('mobile')->width(3);
- $filter->equal('info.is_vip','是否会员')->select(function (){
- return ['否','是'];
- })->width(3);
- $filter->equal('info.platform','是否会员')->select(function (){
- return [1 => '抖音', 2 => '快手'];
- })->width(3);
- });
- $grid->disableCreateButton();
- $grid->disableDeleteButton();
- $grid->disableRowSelector();
- });
- }
- /**
- * Make a show builder.
- *
- * @param mixed $id
- *
- * @return Show
- */
- protected function detail($id)
- {
- return Show::make($id, new User(), function (Show $show) {
- $show->field('id');
- $show->field('nickname');
- $show->field('avatar');
- $show->field('password');
- $show->field('email');
- $show->field('mobile');
- $show->field('open_id');
- $show->field('union_id');
- $show->field('status');
- $show->field('email_verified_at');
- $show->field('remember_token');
- $show->field('created_at');
- $show->field('updated_at');
- });
- }
- /**
- * Make a form builder.
- *
- * @return Form
- */
- protected function form()
- {
- return Form::make(new User(), function (Form $form) {
- $form->display('id');
- $form->text('nickname');
- $form->text('avatar');
- $form->text('password');
- $form->text('email');
- $form->text('mobile');
- $form->text('open_id');
- $form->text('union_id');
- $form->text('status');
- $form->text('email_verified_at');
- $form->text('remember_token');
- $form->display('created_at');
- $form->display('updated_at');
- });
- }
- }
|