1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- namespace App\Admin\Controllers;
- 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;
- use Stancl\Tenancy\Database\Models\Domain;
- class DomainController extends AdminController
- {
- protected $title = 'Domains';
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- $grid = new Grid(new Domain(['tenant']));
- $grid->model()->orderByDesc('id');
- $grid->column('id')->sortable();
- $grid->column('domain')->editable()->copyable();
- $grid->column('tenant.name')->expand(function ($model) {
- $tenants = $model->tenant()->take(10)->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');
- $grid->column('updated_at')->sortable();
- $grid->actions(function (Grid\Displayers\Actions $actions) {
- $actions->disableEdit();
- $actions->disableDelete();
- });
- $grid->filter(function (Grid\Filter $filter) {
- $filter->like('domain');
- });
- return $grid;
- }
- /**
- * Make a show builder.
- *
- * @param mixed $id
- *
- * @return Show
- */
- protected function detail($id)
- {
- $show = new Show(Domain::query()->findOrFail($id));
- $show->field('id');
- $show->field('domain');
- $show->field('created_at');
- $show->field('updated_at');
- $show->panel()->tools(function ($tools) {
- $tools->disableDelete();
- });
- $show->tenant('tenant', function ($tenant) {
- $tenant->id();
- $tenant->name();
- $tenant->tenancy_db_connection();
- $tenant->expired_at();
- $tenant->created_at();
- $tenant->updated_at();
- $tenant->panel()->tools(function ($tools) {
- $tools->disableList();
- $tools->disableEdit();
- $tools->disableDelete();
- });
- });
- return $show;
- }
- protected function form()
- {
- $form = new Form(new Domain());
- $form->text('domain', 'Domain')->rules('required');
- $form->select('tenant_id', 'Tenant ID')
- ->options(Tenant::all()->pluck('name','id'))->rules('required')
- ->default(request()->get('tenant_id'));
- return $form;
- }
- }
|