Laravel расписание карта сайта: генерировать не работает - PullRequest
0 голосов
/ 29 сентября 2019

Я добавил spatie / laravel-sitemap в свое приложение Laravel, и он работает, когда я запускаю команду php artisan sitemap: generate, но я не могу понять, как заставить его работать автоматически с расписанием Kernel.php.

Я добавил команду $ schedule-> ('sitemap: generate') -> hourly ();но он не работает

Консоль / Команды / GenerateSitemap.php

    <?php

    namespace App\Console\Commands;

    use Illuminate\Console\Command;
    use Spatie\Sitemap\SitemapGenerator;

    class GenerateSitemap extends Command
    {
        /**
         * The console command name.
         *
         * @var string
         */
        protected $signature = 'sitemap:generate';

        /**
         * The console command description.
         *
         * @var string
         */
        protected $description = 'Generate the sitemap.';

        /**
         * Execute the console command.
         *
         * @return mixed
         */
        public function handle()
        {
            // modify this to your own needs
            SitemapGenerator::create('mywebsite')
                ->writeToFile(public_path('sitemap.xml'));
        }
    }

Консоль \ Kernel.php


    <?php

    namespace App\Console;

    use Illuminate\Console\Scheduling\Schedule;
    use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

    class Kernel extends ConsoleKernel
    {
        /**
         * The Artisan commands provided by your application.
         *
         * @var array
         */
        protected $commands = [
            Commands\GenerateSitemap::class,
        ];

        /**
         * Define the application's command schedule.
         *
         * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
         * @return void
         */
        protected function schedule(Schedule $schedule)
        {
            $schedule->command('sitemap:generate')->hourly();
        }

        /**
         * Register the commands for the application.
         *
         * @return void
         */
        protected function commands()
        {
            $this->load(__DIR__.'/Commands');

            require base_path('routes/console.php');
        }
    }

Что нужно добавить, чтобы он автоматически генерировалсякарта сайта каждый час?

1 Ответ

0 голосов
/ 30 сентября 2019

Вы должны объявить в проецируемых командах, как это \ App \ Console \ Commands \ GenerateSitemap :: class

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...