abraham foto abraham foto - 8 months ago 56
PHP Question

laravel: scheduler cant find my controller

I have a controller called guzzle controller with a function guzzle. I want to run it every minute. but when i run php artisan schedular:run in the command line. it give me an error that saying"Class guzzleController does not exist"

In my app/kernel.php I have the following code to run the schedule:

protected function schedule(Schedule $schedule){

Is the problem in thew scheduler or on the command ?


You should consider controllers as just a transport layer for your application. Any actual functionality logic should go into your domain classes.

Try refactoring your controller functionality in a way that it consumes, for example, a service class. Then make a command class that utilizes the same service class as well, providing another way to trigger the functionality.

This way, you have the functionality encapsulated in a service class. Both controller and command classes are just consuming that class as just transport means; HTTP requests and CLI commands.

When done with refactoring, you can schedule your command to be run every minute.