laravel 清空各种缓存

暂无标签

//清空各种缓存
public function clear(){
    Artisan::call('cache:clear');
    Artisan::call('config:clear');
    Artisan::call('route:clear');
    Artisan::call('view:clear');
    Artisan::call('clear-compiled');
    Artisan::call('modelCache:clear');
    flash_success('操作成功');
    return redirect()->back();
}

laravel-admin 增加清空缓存按钮

1. app/Admin/bootstrap.php 添加**

use App\Admin\Actions;

Admin::navbar(function (\Encore\Admin\Widgets\Navbar $navbar) {
    $navbar->right(new Actions\ClearCache());
});

2. app/Admin 新建Actions目录,里面新建文件ClearCache.php**

<?php

namespace App\Admin\Actions;

use Encore\Admin\Actions\Action;
use Illuminate\Http\Request;
use Artisan;

class ClearCache extends Action
{
    protected $selector = '.clear-cache';

    public function handle(Request $request)
    {
        Artisan::call('cache:clear');  // 清除cache缓存
        Artisan::call('config:clear'); // 清除配置缓存
        Artisan::call('route:clear');  // 清除路由缓存
        Artisan::call('view:clear');   // 清除视图缓存
        Artisan::call('route:cache');  // 保存路由缓存
        return $this->response()->success('更新完成')->refresh();
    }

    // 弹窗提示
    public function dialog()
    {
        $this->confirm('<span style="font-size:14px;font-weight:500;">清除Cache、配置、网站基本、路由、视图缓存<span>');
    }
    
    // 导航按钮
    public function html()
    {
        return <<<HTML
                <li>
                    <a class="clear-cache" href="#">
                      <span>更新缓存</span>
                    </a>
                </li>
                HTML;
    }
}