|
@@ -5,10 +5,14 @@ namespace App\Admin\Controllers;
|
|
|
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.
|
|
|
*
|
|
@@ -16,24 +20,28 @@ class DomainController extends AdminController
|
|
|
*/
|
|
|
protected function grid()
|
|
|
{
|
|
|
- return Grid::make(new Domain('tenant'), function (Grid $grid) {
|
|
|
- $grid->model()->orderByDesc('id');
|
|
|
-
|
|
|
- $grid->column('id')->sortable();
|
|
|
- $grid->column('domain')->copyable();
|
|
|
- $grid->column('tenant.name', '关联租户');
|
|
|
- $grid->column('created_at');
|
|
|
- $grid->column('updated_at')->sortable();
|
|
|
-
|
|
|
- $grid->disableCreateButton();
|
|
|
- $grid->disableEditButton();
|
|
|
-
|
|
|
- $grid->filter(function (Grid\Filter $filter) {
|
|
|
- $filter->equal('id');
|
|
|
- $filter->like('domain');
|
|
|
- $filter->equal('tenant_id', '关联租户')->select(Tenant::pluck('name', 'id'));
|
|
|
+ $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;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -45,27 +53,30 @@ class DomainController extends AdminController
|
|
|
*/
|
|
|
protected function detail($id)
|
|
|
{
|
|
|
- return Show::make($id, new Domain('tenant'), function (Show $show) {
|
|
|
- $show->field('id');
|
|
|
- $show->field('domain');
|
|
|
- $show->field('tenant.name', '关联租户');
|
|
|
- $show->field('created_at');
|
|
|
- $show->field('updated_at');
|
|
|
+ $show = new Show(Domain::query()->findOrFail($id));
|
|
|
|
|
|
- $show->disableEditButton();
|
|
|
+ $show->field('id');
|
|
|
+ $show->field('domain');
|
|
|
+ $show->field('created_at');
|
|
|
+ $show->field('updated_at');
|
|
|
+ $show->panel()->tools(function ($tools) {
|
|
|
+ $tools->disableDelete();
|
|
|
});
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Make a form builder.
|
|
|
- *
|
|
|
- * @return Form
|
|
|
- */
|
|
|
- protected function form()
|
|
|
- {
|
|
|
- // 保留这个方法,否则删除功能失效.
|
|
|
- return Form::make(new Domain(), function (Form $form) {
|
|
|
|
|
|
+ $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;
|
|
|
}
|
|
|
}
|