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

declare(strict_types=1);

namespace 
AppModels;

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

/**
 * Class Post
 *
 * @property int id
 * @property int topic_id
 * @property int user_id
 * @property string text
 * @property int rating
 * @property int created_at
 * @property string ip
 * @property string brow
 * @property int edit_user_id
 * @property int updated_at
 * @property Collection files
 */
class Post 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/forums';

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

    
/**
     * Возвращает связь пользователей
     */
    
public function editUser(): BelongsTo
    
{
        return 
$this->belongsTo(User::class, 'edit_user_id')->withDefault();
    }

    
/**
     * Возвращает топик
     */
    
public function topic(): BelongsTo
    
{
        return 
$this->belongsTo(Topic::class, 'topic_id')->withDefault();
    }

    
/**
     * Возвращает загруженные файлы
     */
    
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();
    }
}
Онлайн: 2
Реклама