Laravel Scheduling call controller

Kikolce picture Kikolce · Mar 16, 2016 · Viewed 22.2k times · Source

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 uncommented line i get this error:

[ReflectionException]
Class RecurrenceInvoiceController does not exist

and then I insert fully qualified 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 way is correct to call method from Controller from Laravel Task Scheduling.

Answer

Jennifer Miranda Beuses picture Jennifer Miranda Beuses · May 17, 2016

I stumbled months ago with the same problem, until I could fix it. I use laravel 5.2 and the kernel call my drivers this way:

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

I hope this will help someone else ;)