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

declare(strict_types=1);

namespace 
AppModels;

use 
AppTraitsCategoryTreeTrait;
use 
IlluminateDatabaseEloquentCollection;
use 
IlluminateDatabaseEloquentRelationsBelongsTo;
use 
IlluminateDatabaseEloquentRelationsHasMany;
use 
IlluminateDatabaseEloquentRelationsHasOne;

/**
 * Class Load
 *
 * @property int id
 * @property int sort
 * @property int parent_id
 * @property string name
 * @property int count_downs
 * @property int closed
 * @property Load parent
 * @property Collection children
 */
class Load extends BaseModel
{
    use 
CategoryTreeTrait;

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

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

    
/**
     * Возвращает связь родительской категории
     */
    
public function parent(): BelongsTo
    
{
        return 
$this->belongsTo(self::class, 'parent_id')->withDefault();
    }

    
/**
     * Возвращает связь подкатегорий
     */
    
public function children(): HasMany
    
{
        return 
$this->hasMany(self::class, 'parent_id')->orderBy('sort');
    }

    
/**
     * Возвращает количество загрузок за последние 3 дней
     */
    
public function new(): hasOne
    
{
        return 
$this->hasOne(Down::class, 'category_id')
            ->
selectRaw('category_id, count(*) as count_downs')
            ->
where('active'1)
            ->
where('created_at''>'strtotime('-3 day'SITETIME))
            ->
groupBy('category_id');
    }
}
Онлайн: 2
Реклама