A
A
arseniylebedev2022-02-09 17:09:37
PHP
arseniylebedev, 2022-02-09 17:09:37

Z-song / laravel-admin why doesn't makeVisible work on edit form?

<?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;
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
arseniylebedev, 2022-02-09
@arseniylebedev

Got it working
https://github.com/z-song/laravel-admin/issues/2561

/**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new PersonalAccessToken());

        $form->editing(function ($form) {
            $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;
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question