-1

I am attempting to invoke a route as a cron job. Have attempted several guides such as this:

Call laravel controller via command line and https://laracasts.com/discuss/channels/laravel/croning-a-route

Which leads to this addition in Kernel:

protected function schedule(Schedule $schedule) {
    $schedule->call(function () {
        (new Cron_c)->start();
    })->everyMinute();
}

Which does nothing but output 'Callback' when testing using

php /var/www/html/mySite/artisan schedule:run

outputs

[2022-07-11T15:27:50+00:00] Running scheduled command: Callback

The cron job code runs fine when entering the route into the browser and it outputs log info and on screen.

Datadimension
  • 872
  • 1
  • 12
  • 31
  • **DO NOT post images of code, data, error messages, etc.** - copy or type the text into the question. [ask] – Rob Jul 14 '22 at 13:17
  • I didn't downvote but if you're going to blame me for it, maybe I should. Your complaint is about the SO rules which I quoted and linked to. If you have a complaint about the SO rules, take it up with the moderators, not me. – Rob Jul 14 '22 at 16:47
  • [Why not upload images in questions?](https://meta.stackoverflow.com/a/285557) – Rob Jul 14 '22 at 17:12
  • **Which does nothing but output 'Callback' when testing using** What are you expecting from it? Add more to the scope so we can at least reproduce what you are facing. – Salman Malik Jul 15 '22 at 00:32
  • 1
    I wanted to copy-paste the output you're getting so I can start searching and investigating ... but it's an image. – Don't Panic Jul 15 '22 at 07:55

1 Answers1

0

What you are looking for is Laravel Commands: https://laravel.com/docs/9.x/artisan

With php artisan make:command <your Command Name> you can create Commands. Those will be created in the App/Console/Commands directory.

You will there find in the newly created class a function called handle() where you would put your code.

The CLI command to call your function will be set in the property protected $signature = "datadimensionsCommand";, which is prepared for you as well.

So your cronjob would call:


$> php /path/to/your/app/artisan datadimensionsCommand

Checkout the docs for a deeper dive!

helle
  • 11,183
  • 9
  • 56
  • 83