laravel-admin 在列表页添加自定义按钮的例子

吾爱主题 阅读:110 2021-08-25 14:51:00 评论:0

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

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

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 <?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

?
1 2 3 < div class = "btn" >    < a class = "btn btn-sm btn-default pull-right" href = "{{$url}}" rel = "external nofollow" >< i class = "fa {{$icon}}" ></ i > {{$text}}</ a > </ div >

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

?
1 2 3 4 5 6 7 8 9 10 11 $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 在列表页添加自定义按钮的例子就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/hhhzua/article/details/80617454

可以去百度分享获取分享代码输入这里。
声明

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

【腾讯云】云服务器产品特惠热卖中
搜索
标签列表
    关注我们

    了解等多精彩内容