CreateButton.php 1.8 KB
<?php
/**
+-----------------------------------------------------------------------------------------------------------------------
 * 重写 laravel-admin 类
+-----------------------------------------------------------------------------------------------------------------------
 *
 * PHP version 7
 *
 * @category  App\Admin\Rewrite\Grid\Tools
 * @package   App\Admin\Rewrite\Grid\Tools
 * @author    Richer <yangzi1028@163.com>
 * @date      2021年12月20日14:44:55
 * @copyright 2021-2022 Richer (http://www.Richer.com/)
 * @license   http://www.Richer.com/ License
 * @link      http://www.Richer.com/
 */
namespace App\Admin\Rewrite\Grid\Tools;

use Encore\Admin\Grid\Tools\CreateButton as Base;
use Illuminate\Support\Arr;

/**
 * Class CreateButton
 *
 * @category  App\Admin\Rewrite\Grid\Tools
 * @package   App\Admin\Rewrite\Grid\Tools
 * @author    Richer <yangzi1028@163.com>
 * @date      2021年12月20日14:44:55
 * @copyright 2021-2022 Richer (http://www.Richer.com/)
 * @license   http://www.Richer.com/ License
 * @link      http://www.Richer.com/
 */
class CreateButton extends Base
{
   /**
     * Render CreateButton.
     *
     * @return string
     */
    public function render()
    {
        if (!$this->grid->showCreateBtn()) {
            return '';
        }

        $url = "{$this->grid->getCreateUrl()}";
        $params = explode('?', request()->getUri());

        // 如果有参数
        if (count($params) > 1) {
            $url .= '?'.Arr::last($params);
        }
        $action = __('new');

        return <<<EOT

<div class="btn-group pull-right grid-create-btn" style="margin-right: 10px">
    <a href="{$url}" class="btn btn-success grid-row-new" title="{$action}">
        <i class="fa fa-plus"></i><span class="hidden-xs">&nbsp;&nbsp;{$action}</span>
    </a>
</div>

EOT;
    }
}