<?php
namespace App\Admin\Controllers;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use Laravel\Sanctum\PersonalAccessToken;
class PersonalAccessTokensController extends AdminController
{
/**
* Title for current resource.
*
* @var string
*/
protected $title = 'Токены доступа';
/**
* Make a grid builder.
*
* @return Grid
*/
protected function grid()
{
$grid = new Grid(new PersonalAccessToken());
$grid->model()->collection(function ($collection) {
return $collection->makeVisible('token'); // Этот makeVisible работает
});
$grid->column('id', __('Id'));
$grid->column('tokenable_type', __('Tokenable type'));
$grid->column('tokenable_id', __('Tokenable id'));
$grid->column('name', __('Name'));
$grid->column('token', __('Token'));
$grid->column('abilities', __('Abilities'));
$grid->column('last_used_at', __('Last used at'));
$grid->column('created_at', __('Created at'));
$grid->column('updated_at', __('Updated at'));
return $grid;
}
/**
* Make a show builder.
*
* @param mixed $id
* @return Show
*/
protected function detail($id)
{
// Тут токен почему-то тоже отображается без makeVisible
$show = new Show(PersonalAccessToken::findOrFail($id));
$show->field('id', __('Id'));
$show->field('tokenable_type', __('Tokenable type'));
$show->field('tokenable_id', __('Tokenable id'));
$show->field('name', __('Name'));
$show->field('token', __('Token'));
// $show->field('abilities', __('Abilities'));
$show->field('last_used_at', __('Last used at'));
$show->field('created_at', __('Created at'));
$show->field('updated_at', __('Updated at'));
return $show;
}
/**
* Make a form builder.
*
* @return Form
*/
protected function form()
{
$form = new Form(new PersonalAccessToken());
// Здесь makeVisible не работает, в форме редактирования его не видно
$form->model()->makeVisible('token');
$form->text('tokenable_type', __('Tokenable type'));
$form->text('tokenable_id', __('Tokenable id'));
$form->text('name', __('Name'));
$form->text('token', __('Token'));
// $form->display('abilities', __('Abilities'));
$form->datetime('last_used_at', __('Last used at'));
$form->datetime('created_at', __('Created at'));
$form->datetime('updated_at', __('Updated at'));
return $form;
}
}