HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/farmfun.komma.pro/app/Komma/ProductCategories/Models/ProductCategory.php
<?php

namespace App\Komma\ProductCategories\Models;

use App\Komma\Documents\DocumentsTrait;
use App\Komma\Documents\Kms\DocumentableInterface;
use App\Komma\Globalization\Languages\Models\Language;
use App\Komma\Kms\Core\AbstractTranslatableModel;
use App\Komma\Kms\Core\Entities\DisplayNameInterface;
use App\Komma\Kms\Core\Entities\DisplayNameTrait;
use App\Komma\Kms\Core\Tree\NestedSets\Nodes\TreeModelInterface;
use App\Komma\Kms\Core\Tree\NestedSets\Nodes\TreeModelLogicTrait;
use App\Komma\Products\Models\Product;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;

/**
 * Class ProductCategory
 *
 * @property-read \App\Komma\Globalization\Languages\Models\Language[] $languages
 * @property-read \App\Komma\ProductCategories\Models\ProductCategoryTranslation $translation
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\ProductCategories\Models\ProductCategoryTranslation[] $translations
 * @mixin \Eloquent
 * @property int $id
 * @property int $active
 * @property \Carbon\Carbon|null $created_at
 * @property \Carbon\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\ProductCategories\Models\ProductCategory whereActive($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\ProductCategories\Models\ProductCategory whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\ProductCategories\Models\ProductCategory whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\ProductCategories\Models\ProductCategory whereUpdatedAt($value)
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Documents\Models\Document[] $documents
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Documents\Models\Document[] $images
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\ProductCategories\Models\ProductCategory newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\ProductCategories\Models\ProductCategory newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\ProductCategories\Models\ProductCategory query()
 */
final class ProductCategory extends AbstractTranslatableModel implements DocumentableInterface, DisplayNameInterface, TreeModelInterface
{
    use DocumentsTrait;
    use DisplayNameTrait;
    use TreeModelLogicTrait;

    protected $class = self::class;

    protected $protected = ['id', 'created_at', 'updated_at'];

    /**
     * Gets the translation models for this model
     *
     * @return HasMany that resolves to AbstractTranslationModel instances
     */
    public function translations(): HasMany
    {
        return $this->hasMany(ProductCategoryTranslation::class);
    }

    public function languages(): BelongsToMany
    {
        return $this->belongsToMany(Language::class, 'post_translations')
            ->withPivot('name', 'description')
            ->withTimestamps();
    }

    public function products(): BelongsToMany
    {
        return $this->belongsToMany(Product::class, 'product_category_products')
            ->orderBy('product_category_products.sort_order', 'asc');
    }

    /**
     * Return a number, representing some color that represents
     * the status if the TreeModel. Used at the frontend
     *
     * @return mixed
     */
    public function getColorStatusNumber(): int
    {
        return $this->active ?: 0;
    }
}