laravel / cron設定

NO IMAGE

◯〜〜::setLocale($locale) エラー

“require”: {

“symfony/translation”: “4.3.8”,
}

◯コマンドのクラス作成
$ php artisan make:command TestCommand

 

namespace App\Console\Commands;

use Illuminate\Console\Command;

class TestCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    //コマンド名を設定(元:command:name→変更後:command:testcommand)
    protected $signature = 'command:testcommand';  

    /**
     * The console command description.
     *
     * @var string
     */
    //コマンドの説明(元:Command description→変更後:testcommandのコマンド説明)
    protected $description = 'testcommandのコマンド説明';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {

         // ここに処理を記述
         echo "testcommand実行!!\n";
    }
}

3.コマンドの登録、スケジュールの登録

記述した処理のコマンド登録、cronで実行するスケジュールの登録

path_to_project/app/Console/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 = [
        \App\Console\Commands\TestCommand::class,   //コマンドの登録

    ];


    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        // スケジュールの登録(「->daily()」は毎日深夜12時に実行)
        $schedule->command('command:testcommand')->daily();
    }

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

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

$ crontab -e

* * * * * php /{path_to_project}/artisan schedule:run >> /dev/null 2>&1

 

パスを通してないため(MAMP)

* * * * */Applications/MAMP/bin/php/php7.2.10/bin/php /{path_to_project}/artisan schedule:run >> /dev/null 2>&1