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

declare(strict_types=1);

namespace 
AppTraits;

use 
AppModelsComment;
use 
IlluminateDatabaseEloquentRelationsHasMany;
use 
IlluminateDatabaseEloquentRelationsMorphMany;

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

    
/**
     * Возвращает последние комментарии
     *
     * @return HasMany<Comment, $this>
     */
    
public function lastComments(int $limit 15): HasMany
    
{
        return 
$this->hasMany(Comment::class, 'relate_id')
            ->
where('relate_type'self::$morphName)
            ->
orderBy('created_at''desc')
            ->
with('user')
            ->
limit($limit);
    }
}
Онлайн: 0
Реклама