為了添加自定義按鈕,按官方文檔分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="{{$url}}" rel="external nofollow" >i class="fa {{$icon}}">/i> {{$text}}/a>
/div>
3、在model-grid引入這個(gè)工具:
$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 在列表頁(yè)添加自定義按鈕的例子就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
您可能感興趣的文章:- 淺談laravel-admin的sortable和orderby使用問(wèn)題
- laravel-admin的多級(jí)聯(lián)動(dòng)方法
- laravel-admin 實(shí)現(xiàn)給grid的列添加行數(shù)序號(hào)的方法