Просмотр файла app/Console/Commands/DeleteReaders.php

Размер файла: 958B
  1. <?php
  2.  
  3. namespace App\Console\Commands;
  4.  
  5. use App\Models\Reader;
  6. use Illuminate\Console\Command;
  7.  
  8. class DeleteReaders extends Command
  9. {
  10. /**
  11. * The name and signature of the console command.
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'delete:readers';
  16.  
  17. /**
  18. * The console command description.
  19. *
  20. * @var string
  21. */
  22. protected $description = 'Delete readers';
  23.  
  24. /**
  25. * Create a new command instance.
  26. *
  27. * @return void
  28. */
  29. public function __construct()
  30. {
  31. parent::__construct();
  32. }
  33.  
  34. /**
  35. * Удаляет старые записи статистики просмотров и скачиваний
  36. *
  37. * @return int
  38. */
  39. public function handle()
  40. {
  41. Reader::query()
  42. ->where('created_at', '<', strtotime('-6 month', SITETIME))
  43. ->delete();
  44.  
  45. $this->info('Readers successfully deleted.');
  46.  
  47. return 0;
  48. }
  49. }