Help us understand the problem. What is going on with this article?

laravel-admin でRowAction の表示方式を変更する

環境

  • Laravel Framework 8.2.0
  • laravel-admin 1.8.4

経緯

laravel-admin 1.8.4 では RowAction はハンバーガーメニューみたいな形式になってるが、ドキュメントの TOP のスクリーンショットにあるようなリンク形式にしたくて若干ハマった。
2020-09-14 23_40_02-Window.png
こんなの

変更方法

config/admin.php
    /*
    |--------------------------------------------------------------------------
    | The global Grid action display class.
    |--------------------------------------------------------------------------
    */
    'grid_action_class' => \Encore\Admin\Grid\Displayers\DropdownActions::class,

config/admin.php 内の grid_action_class\Encore\Admin\Grid\Displayers\Actions::class に変更するだけで良かった。

改めてドキュメントを見るとこの辺で grid_action_class について書いてるけど古い方式だから(?)触れられていないのかな?
https://laravel-admin.org/docs/en/model-grid-custom-actions#Old%20version%20compatible

もう少しカスタマイズする

Actions::render(View|Edit|Delete) をオーバーライドする。

renderDelete はクラスやデータ属性を下手に消すと削除用のスクリプトが動かなくなるので注意。

CustomActions.php
<?php

namespace App\Admin\Grid\Displayers;

use Encore\Admin\Grid\Displayers\Actions;

class CustomActions extends Actions
{
    protected function renderView()
    {
        return <<<EOT
<a href="{$this->getResource()}/{$this->getRouteKey()}" class="{$this->grid->getGridRowName()}-view btn btn-sm btn-default">
    <i class="fa fa-eye"></i> View
</a>
EOT;
    }

    protected function renderEdit()
    {
        return <<<EOT
<a href="{$this->getResource()}/{$this->getRouteKey()}/edit" class="{$this->grid->getGridRowName()}-edit btn btn-sm btn-default">
    <i class="fa fa-edit"></i> Edit
</a>
EOT;
    }

    protected function renderDelete()
    {
        $this->setupDeleteScript();

        return <<<EOT
<a href="javascript:void(0);" data-id="{$this->getKey()}" class="{$this->grid->getGridRowName()}-delete btn btn-sm btn-default">
    <i class="fa fa-trash"></i> Delete
</a>
EOT;
    }
}

config/admin.php を修正。

     /*
     |--------------------------------------------------------------------------
     | The global Grid action display class.
     |--------------------------------------------------------------------------
     */
-    'grid_action_class' => \Encore\Admin\Grid\Displayers\Actions::class,
+    'grid_action_class' => \App\Admin\Grid\Displayers\CustomActions::class,

127.0.0.1_8000_admin_auth_permissions(iPad).png

tateren
正規表現と文字コードが好き
http://tateren.hateblo.jp
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした