informatica:programacion:php:frameworks:laravel:comandos
Comandos en Laravel
Creando comandos para Artisan
php artisan make:command RemoveOldProducts
Se creará en app/Console/Commands/RemoveOldProducts:
// Indica cómo se usa el comando protected $signature = 'products:remove-old {--days=7 : The days after which the products will be removed}'; protected $description = 'Remove old products'; // // Lo que Laravel ejecutará al llamar al comando public function handle() { $deadline = now()->subDays($this->option("days")); $counter = Product::whereDate("updated_at", "<=", $deadline)->delete(); $this->info("Done! {$counter} products were removed."); }
Miramos nuestra lista de comandos para ver si aparece el recién creado:
php artisan
Podemos ver la ayuda:
php artisan products:remove-old --help
Finalmente, para usar el comando:
php artisan products:remove-old
informatica/programacion/php/frameworks/laravel/comandos.txt · Última modificación: por tempwin
