Parcourir la source

增加刷新菜单缓存命令

jqh il y a 5 ans
Parent
commit
593c6724dd

+ 2 - 1
src/AdminServiceProvider.php

@@ -29,6 +29,7 @@ class AdminServiceProvider extends ServiceProvider
         Console\IdeHelperCommand::class,
         Console\FormCommand::class,
         Console\ActionCommand::class,
+        Console\MenuCacheCommand::class,
     ];
 
     /**
@@ -83,7 +84,7 @@ class AdminServiceProvider extends ServiceProvider
      */
     public function register()
     {
-        require __DIR__.'/Support/AdminSection.php';
+        require_once __DIR__.'/Support/AdminSection.php';
 
         $this->registerExtensionProviders();
         $this->loadAdminAuthConfig();

+ 1 - 1
src/Console/IdeHelperCommand.php

@@ -30,7 +30,7 @@ class IdeHelperCommand extends Command
      *
      * @var string
      */
-    protected $description = 'Make ide-helper file.';
+    protected $description = 'Create the ide-helper file';
 
     /**
      * @var array

+ 41 - 0
src/Console/MenuCacheCommand.php

@@ -0,0 +1,41 @@
+<?php
+
+namespace Dcat\Admin\Console;
+
+use Illuminate\Console\Command;
+
+class MenuCacheCommand extends Command
+{
+    /**
+     * The console command name.
+     *
+     * @var string
+     */
+    protected $signature = 'admin:menu-cache';
+
+    /**
+     * The console command description.
+     *
+     * @var string
+     */
+    protected $description = 'Flush the menu cache';
+
+    /**
+     * Execute the console command.
+     *
+     * @return void
+     */
+    public function handle()
+    {
+        $menuModel = config('admin.database.menu_model');
+        $menuModel = new $menuModel();
+
+        $menuModel->flushCache();
+
+        $this->info('Menu cache cleared!');
+
+        $menuModel->allNodes();
+
+        $this->info('Menu cached successfully!');
+    }
+}

+ 2 - 4
src/Models/MenuCache.php

@@ -25,11 +25,9 @@ trait MenuCache
     }
 
     /**
-     * Delete all items from the cache.
-     *
-     * @return bool
+     * @return bool|void
      */
-    public function destroyCache()
+    public function flushCache()
     {
         if (! $this->enableCache()) {
             return;