nscode
nscode

Reputation: 157

where to put scraper logic in Laravel?

I want to regularly (once a day) scrape data and insert into the database table which I want to completely clear before each insertion of the scraped data. Which in turn I want to present with my presentation logic.

I'm not sure how to structure this.

For the presentation logic I guess it's simple, I make a request to a controller to get all data from the DB, and then I just present it with views.

For the scraper logic, I'm not so sure.. Since I want to regularly scrape (cron job?), I heard about Laravel scheduler, from a tutorial I saw, the logic was put into a command file.. so that's where I should put my php script for the scheduler to run?

Or do I need to create a model and put the logic there, use a controller to insert it into the DB? If so, how do I schedule it as a cron job?

Thanks.

Upvotes: 0

Views: 350

Answers (1)

PtrTon
PtrTon

Reputation: 3835

Yes, you should use an artisan command which contains the logic for scraping (or calls a service which contains that logic). That command can then be run either manually or via the scheduler which should be called via a cronjob.

Upvotes: 1

Related Questions