0
votes

I have built a website in laravel and i am not hosting my website. I have a CPanel where i have a section for cron jobs But i cannot figure out how to write my cronjobs in laravel and execute them from this cpanel.

Any help is appreciated..

Thanks

1

1 Answers

1
votes

Sameer - If you were looking to trigger certain methods via cron, you would need to set up the particular actions you want to take place and make it accessible to a URL.

It's very similar to having your application do something when a particular URL is hit. For example, when a user hits auth/login your site should run through the proper routes and controller methods to display a login form.

So say you wanted to have a cronjob that would delete all users that don't complete the email activation of their account. The steps might look something like this:

  1. Set up your laravel app to filter through your users and retrieve all the ones that aren't activated.
  2. Run the method to delete them from the url http://example.com/actions/delete-unactivated-users
  3. Set up your cronjob in cPanel to hit that particular URL every 24 hours

The concept with a cron from cPanel is that it will simply trigger a particular url at a given interval. It's really up to you and your Laravel app to take the steps once the URL is hit.

Does that help?