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/Pages/Models/Page.php
<?php
/**
 * @author      Komma <info@komma.pro>
 * @copyright   (c) 2012-2016, Komma
 */

namespace App\Komma\Pages\Models;

use App\Komma\Components\Component\ComponentableInterface;
use App\Komma\Components\Component\ComponentableTrait;
use App\Komma\Documents\DocumentsTrait;
use App\Komma\Documents\Kms\DocumentableInterface;
use App\Komma\Documents\Models\Document;
use App\Komma\Globalization\Languages\Models\Language;
use App\Komma\Kms\Core\Entities\DisplayNameInterface;
use App\Komma\Kms\Core\Entities\DisplayNameTrait;
use App\Komma\Kms\Core\Tree\NestedSets\Nodes\AbstractTranslatableTreeModel;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;

/**
 * Class Page
 *
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Globalization\Languages\Models\Language[] $languages
 * @property-read \App\Komma\Sites\Models\Site $site
 * @property-read \App\Komma\Pages\Models\PageTranslation $translation
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Pages\Models\PageTranslation[] $translations
 * @mixin \Eloquent
 * @property int $id
 * @property int $site_id
 * @property int $active
 * @property int $seo_page
 * @property string|null $code_name
 * @property int|null $lft
 * @property int|null $rgt
 * @property int|null $tree
 * @property bool $has_wildcard
 * @property \Carbon\Carbon|null $created_at
 * @property \Carbon\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Pages\Models\Page whereActive($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Pages\Models\Page whereCodeName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Pages\Models\Page whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Pages\Models\Page whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Pages\Models\Page whereLft($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Pages\Models\Page whereRgt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Pages\Models\Page whereSiteId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Pages\Models\Page whereTree($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Pages\Models\Page 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
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Components\Component\Component[] $components
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Pages\Models\Page newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Pages\Models\Page newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Pages\Models\Page query()
 */
final class Page extends AbstractTranslatableTreeModel implements DocumentableInterface, DisplayNameInterface, ComponentableInterface
{
    use DocumentsTrait;
    use DisplayNameTrait;
    use ComponentableTrait;

    protected $table = 'pages';

    protected $class = self::class;

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

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

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

    /**
     * Get the documents belonging to this model
     *
     * @return MorphMany
     */
    public function heroImages():MorphMany
    {
        return $this->morphMany(Document::class, 'documentable')
            ->where('key', 'Documents-hero_images')
            ->orderBy('sort_order');
    }

    public function __get($key)
    {
        if ($key == 'parent_id') {
            if ($this::find($this->id)) {
                return $this->getParentId();
            }
        }

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