Yes, you can split the process into smaller commands and run them programmatically using Laravel's Artisan command. To avoid timeouts, you can use Laravel's queue system to run the commands in the background. Here's an example of how you can modify your code to achieve this:
- Create a new command to inspect a single category:
php artisan make:command InspectCategory --command=inspect:category
- Modify your
InspectAllCategoriescommand to dispatch jobs to the queue instead of running them directly:
// App\Console\Commands\InspectAllCategories
foreach($categories as $category) {
dispatch(new InspectCategory($category));
}
- Modify your
InspectCategorycommand to inspect a single category:
// App\Console\Commands\InspectCategory
public function __construct(Category $category)
{
$this->category = $category;
}
public function handle()
{
$this->category->inspect();
}
- Run the queue worker to process the jobs:
php artisan queue:work
This will run the jobs in the background and avoid timeouts. You can also configure the queue to use a different driver (e.g. Redis) for better performance.