TruncateOldItems.php 664 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Models\Promotion;
  5. class TruncateOldItems extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'items:truncate';
  13. /**
  14. * The console command description.
  15. *
  16. * @var string
  17. */
  18. protected $description = 'Command description';
  19. /**
  20. * Execute the console command.
  21. *
  22. * @return int
  23. */
  24. public function handle()
  25. {
  26. Promotion::where('fin', '<', \Carbon\Carbon::now())->each(function ($item) {
  27. $item->delete();
  28. });
  29. }
  30. }