Вход Регистрация
Файл: app/Console/Commands/DeleteFiles.php
Строк: 37
<?php

namespace AppConsoleCommands;

use 
AppModelsFile;
use 
IlluminateConsoleCommand;
use 
SymfonyComponentConsoleCommandCommand as SymfonyCommand;

class 
DeleteFiles extends Command
{
    
/**
     * The name and signature of the console command.
     */
    
protected $signature 'delete:files';

    
/**
     * The console command description.
     */
    
protected $description 'Delete unattached files';

    
/**
     * Удаляет не прикрепленные файлы
     */
    
public function handle(): int
    
{
        
$files File::query()
            ->
where('relate_id'0)
            ->
where('created_at''<'now()->subDay())
            ->
get();

        foreach (
$files as $file) {
            
$file->delete();
        }

        
$this->info('Files successfully deleted.');

        return 
SymfonyCommand::SUCCESS;
    }
}
Онлайн: 1
Реклама