123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- namespace App\Admin\Controllers;
- use App\Models\GlobalUser;
- use App\Models\Tenant;
- use Encore\Admin\Controllers\AdminController;
- use Encore\Admin\Form;
- use Encore\Admin\Grid;
- use Encore\Admin\Show;
- use Encore\Admin\Widgets\Table;
- class GlobalUserController extends AdminController
- {
- protected $title = '全局用户';
- protected $description = '';
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- $grid = new Grid(new GlobalUser(['tenant']));
- $grid->model()->orderByDesc('created_at');
- $grid->column('id');
- $grid->column('username')->copyable();
- $grid->column('tenant.name')->expand(function ($model) {
- $tenants = $model->tenant()->get()->map(function ($tenant) {
- return $tenant->only(['id', 'name', 'tenancy_db_connection', 'expired_at']);
- });
- return new Table(['ID', 'Name', 'Db_connection', 'expired_at'], $tenants->toArray());
- });
- $grid->column('created_at')->datetime();
- $grid->column('updated_at')->datetime();
- $grid->actions(function (Grid\Displayers\Actions $actions) {
- $actions->disableDelete();
- });
- $grid->filter(function (Grid\Filter $filter) {
- $filter->like('username');
- $filter->equal('tenant_id')->select(Tenant::query()->pluck('name', 'id'));
- });
- return $grid;
- }
- /**
- * Make a show builder.
- *
- * @param mixed $id
- *
- * @return Show
- */
- protected function detail($id)
- {
- $show = new Show(GlobalUser::query()->findOrFail($id));
- $show->field('id');
- $show->field('username');
- $show->field('created_at');
- $show->field('updated_at');
- $show->tenant('tenant', function ($tenant) {
- $tenant->id();
- $tenant->name();
- $tenant->tenancy_db_connection();
- $tenant->expired_at();
- $tenant->panel()->tools(function ($tools) {
- $tools->disableList();
- $tools->disableEdit();
- $tools->disableDelete();
- });
- });
- return $show;
- }
- /**
- * Make a form builder.
- *
- * @return Form
- */
- protected function form()
- {
- $form = new Form(new GlobalUser());
- $form->text('username')->placeholder('unique email or mobile')->rules(function ($form) {
- return 'required|unique:global_users,username,' . $form->model()->id;
- })->required();
- $form->select('tenant_id', 'Tenant')
- ->options(function () {
- return Tenant::all()->pluck('name', 'id')->toArray();
- })
- ->required();
- return $form;
- }
- }
|