为了添加自定义按钮,按官方文档分4步走:

1、先定义工具类app/Admin/Extensions/Tools/ShowArtwork.php:

<?php

namespace App\Admin\Extensions\Tools;

use Encore\Admin\Admin;
use Encore\Admin\Grid\Tools\AbstractTool;
use Illuminate\Support\Facades\Request;

class ShowArtwork extends AbstractTool
{
  protected $url;
  protected $icon;
  function __construct($url,$icon,$text)
  {
    $this->url = $url;
    $this->icon = $icon;
    $this->text = $text;
  }

  public function render()
  {
    $url = $this->url;
    $icon = $this->icon;
    $text = $this->text;
    return view('admin.tools.button', compact('url','icon','text'));
  }
}

2、定义试图文件:resources/views/admin/tools/button.blade.php

<div class="btn">
  <a class="btn btn-sm btn-default pull-right" href="https://www.atool.online/article/{{$url}}" rel="external nofollow" ><i class="fa {{$icon}}"></i> {{$text}}</a>
</div>

3、在model-grid引入这个工具:

      $grid->tools(function ($tools)use($artworkid) {
        $url = "/admin/artimage";
        $icon = "fa-backward";
        $text = "Back";
        $tools->append(new ShowArtwork($url,$icon,$text));

        $url = "/admin/artimage/".$artworkid."/view";
        $icon = "fa-eye";
        $text = "Show Artwork";
        $tools->append(new ShowArtwork($url,$icon,$text));
      });

大功告成!

以上这篇laravel-admin 在列表页添加自定义按钮的例子就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持阿兔在线工具。

点赞(0)

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部