Laravel Call Scheduler

I work with Laravel Task Scheduling, but I have a problem when I call some method from my controller.

protected function schedule(Schedule $schedule)
{
    $schedule->call('UserController@deleteInactiveUsers')->everyMinute();
    //$schedule->call('App\Http\Controllers\UserController@deleteInactiveUsers')->everyMinute();
}

When I call with an undocumented string, I get this error:

[ReflectionException]
Class RecurrenceInvoiceController does not exist

and then I insert the full namespace path, and then I get this error:

[PDOException] SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known

AND

[ErrorException] PDO::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known 

Where is the problem? Which method is correct for calling a method from a controller from Laravel Task Scheduling.

+11
source share
5 answers

I stumbled a few months ago with the same problem until I could fix it. I am using laravel 5.2, and the kernel calls my drivers as follows:

$schedule->call('App\Http\Controllers\MyController@MyAction')->everyMinute();

I hope this helps someone else;)

+20

: composer update, composer dump-autoload.

, , 2002:

MySQL "(. ( MySQL).

.env

+1

. :

public function handle()
    {
        $currency                = new Currency();
        $currency->currency_name = 'EUR';
        $currency->save();

        $this->info('New currency is successfully generated!');
    }

laravel/app/Console/Commands. Kernel > schedule(). .

handle(), :

File::put(base_path() . '/storage/logs/test_logs.txt', 'Test log ' . Carbon::now()->format('Y-m-d H:i:s') . PHP_EOL);

. Models db → , .

0

OK. . Docker Cron. Cron MySQL. .

0

kernel.php

$schedule-> ( 'App\Http\\YourController @') → everyMinute();

:

localhost , , cronjob,

php -d register_argc_argv = On / home / iflasity / public_html / foldername / artisan schedule: run> / dev / null 2> & 1

cd / home / iflasity / public_html / foldername && artisan schedule php: run / dev / null 2> & 1

0
source

All Articles