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/slenders.komma.pro/app/Komma/Shop/_Categories/Models/Category.php
<?php
namespace App\Komma\Shop\Categories\Models;

use App\Komma\Documents\Kms\DocumentableInterface;
use App\Komma\Documents\Models\Document;
use App\Komma\Kms\Core\Entities\DisplayNameTrait;
use App\Komma\Kms\Core\Tree\NestedSets\Nodes\AbstractTranslatableTreeModel;
use App\Komma\Globalization\Languages\Models\Language;
use App\Komma\Shop\Products\Product\Product;
use App\Komma\Shop\Products\ProductComposite\ProductComposite;
use App\Komma\Shop\Products\ProductGroup\ProductGroup;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Laravel\Scout\Searchable;

/**
 * Class Category
 *
 * @package App\Komma\Shop\Categories\Models
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\ImageProcessing\Models\Image[] $images
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Globalization\Languages\Models\Language[] $languages
 * @property-read \App\Komma\Shop\Categories\Models\CategoryTranslation $translation
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Shop\Categories\Models\CategoryTranslation[] $translations
 * @mixin \Eloquent
 * @property int $id
 * @property string $code_name
 * @property int $active
 * @property int|null $lft
 * @property int|null $rgt
 * @property int|null $tree
 * @property \Carbon\Carbon|null $created_at
 * @property \Carbon\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Shop\Categories\Models\Category whereActive($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Shop\Categories\Models\Category whereCodeName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Shop\Categories\Models\Category whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Shop\Categories\Models\Category whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Shop\Categories\Models\Category whereLft($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Shop\Categories\Models\Category whereRgt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Shop\Categories\Models\Category whereSiteId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Shop\Categories\Models\Category whereTree($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Shop\Categories\Models\Category whereUpdatedAt($value)
 * @property int|null $site_id
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Shop\Products\ProductComposite\ProductComposite[] $product_composites
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Shop\Products\ProductGroup\ProductGroup[] $product_groups
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Shop\Products\Product\Product[] $products
 * @property-read \App\Komma\Sites\Models\Site|null $site
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Documents\Models\Document[] $documents
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Shop\Categories\Models\Category newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Shop\Categories\Models\Category newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Shop\Categories\Models\Category query()
 */
class Category extends AbstractTranslatableTreeModel implements DocumentableInterface
{
    use Searchable;
    use DisplayNameTrait;

    public function searchableAs()
    {
        return 'category_index';
    }

    public function toSearchableArray()
    {
        return [
          'id' => $this->id,
          'active' => $this->active,
          'code_name' => $this->code_name,
          'lft' => $this->lft,
          'rgt' => $this->rgt,
          'tree' => $this->tree
        ];
    }

    protected $table = 'product_categories';
    protected $class = Category::class;


    protected $fillable = ['active', 'lft', 'rgt', 'tree', 'code_name'];

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

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

    /**
     * Get the documents from the current model
     *
     * @return MorphMany
     */
    public function documents():MorphMany
    {
        return $this->morphMany(Document::class, 'documentable');
    }

    /**
     * Get the products related to this category
     */
    public function products():MorphToMany
    {
        return $this->morphedByMany(Product::class, 'product_categorizable', 'product_categorizables');
    }

    /**
     * Get the products related to this category
     */
    public function product_groups():MorphToMany
    {
        return $this->morphedByMany(ProductGroup::class, 'product_categorizable', 'product_categorizables');
    }

    /**
     * Get the products related to this category
     */
    public function product_composites():MorphToMany
    {
        return $this->morphedByMany(ProductComposite::class, 'product_categorizable', 'product_categorizables');
    }

    public function __get($key)
    {
        if($key == "title") {
            if($this->translation) {
                return $this->translation->name;
            } else if($this->code_name != '') {
                return $this->code_name;
            }
        }

        return parent::__get($key);
    }
}