Вход Регистрация
Файл: app/Models/Photo.php
Строк: 59
<?php

declare(strict_types=1);

namespace 
AppModels;

use 
AppTraitsConvertVideoTrait;
use 
AppTraitsUploadTrait;
use 
IlluminateDatabaseEloquentCollection;
use 
IlluminateDatabaseEloquentRelationsMorphMany;
use 
IlluminateDatabaseEloquentRelationsMorphOne;

/**
 * Class Photo
 *
 * @property int id
 * @property int user_id
 * @property string title
 * @property string text
 * @property int created_at
 * @property int rating
 * @property int closed
 * @property int count_comments
 * @property Collection files
 */
class Photo extends BaseModel
{
    use 
ConvertVideoTrait;
    use 
UploadTrait;

    
/**
     * Indicates if the model should be timestamped.
     */
    
public $timestamps false;

    
/**
     * The attributes that aren't mass assignable.
     */
    
protected $guarded = [];

    
/**
     * Директория загрузки файлов
     */
    
public string $uploadPath '/uploads/photos';

    
/**
     * Morph name
     */
    
public static string $morphName 'photos';

    
/**
     * Возвращает комментарии фотографий
     */
    
public function comments(): MorphMany
    
{
        return 
$this->morphMany(Comment::class, 'relate')->with('relate');
    }

    
/**
     * Возвращает загруженные файлы
     */
    
public function files(): MorphMany
    
{
        return 
$this->morphMany(File::class, 'relate');
    }

    
/**
     * Возвращает связь с голосованием
     */
    
public function polling(): morphOne
    
{
        return 
$this->morphOne(Polling::class, 'relate')->where('user_id'getUser('id'));
    }

    
/**
     * Удаление фото и загруженных файлов
     */
    
public function delete(): ?bool
    
{
        
$this->files->each(static function (File $file) {
            
$file->delete();
        });

        return 
parent::delete();
    }
}
Онлайн: 4
Реклама