jaahvicky
jaahvicky

Reputation: 448

Running an endpoint as a cron job

I have an endpoint - http://jobsapi.dev/api/v1/jobs and I would like to run this endpoint as a cron on my server. I have created a fetchjobs command to run via php artisan.

From the docs its says that I must put logic of the command in the handle method of the command class. Question is do I need to move my code from my controller method(that has endpoint logic) and put it in the handle method which i doubt is the right way of doing it, or they is a laravel way of calling the controller method into the method below.

public function handle() {
      //IS THIS WHERE I NEED TO MOVE MY CODE TO?    

}

Thank you in advance.

Upvotes: 2

Views: 1013

Answers (1)

Alexey Mezenin
Alexey Mezenin

Reputation: 163898

Better practice is to create another class or helper and keep logic there. Then you can use this logic both inside controller and command. In this case you will avoid code duplication.

Upvotes: 3

Related Questions