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

namespace App\KommaApp\Pages\Models;

use App\KommaApp\Documents\Kms\DocumentableInterface;
use App\KommaApp\Documents\Models\Document;
use App\KommaApp\Images\Models\Image;
use App\KommaApp\Kms\Core\HasImagesInterface;
use App\KommaApp\Kms\Core\NestedSets\Nodes\TranslatableEloquentNode;
use App\KommaApp\Languages\Models\Language;
use App\KommaApp\Sites\Models\Site;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;

/**
 * Class Page
 *
 * @package App\KommaApp\Pages\Models
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\KommaApp\Images\Models\Image[] $images
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\KommaApp\Languages\Models\Language[] $languages
 * @property-read \App\KommaApp\Sites\Models\Site $site
 * @property-read \App\KommaApp\Pages\Models\PageTranslation $translation
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\KommaApp\Pages\Models\PageTranslation[] $translations
 * @mixin \Eloquent
 * @property int $id
 * @property int $site_id
 * @property int $active
 * @property string|null $code_name
 * @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\KommaApp\Pages\Models\Page whereActive($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Pages\Models\Page whereCodeName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Pages\Models\Page whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Pages\Models\Page whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Pages\Models\Page whereLft($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Pages\Models\Page whereRgt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Pages\Models\Page whereSiteId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Pages\Models\Page whereTree($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\Pages\Models\Page whereUpdatedAt($value)
 */
class Page extends TranslatableEloquentNode implements HasImagesInterface, DocumentableInterface
{
    protected $table = 'pages';
    protected $class = Page::class;
    /*
    * Transient properties on Eloquent models
    * These are not saved to database.
    */
    public $thumbnail = false;
//    public $parent_id;


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

    public function site(): BelongsTo
    {
        return $this->belongsTo(Site::class);
    }

    /**
     * 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 images from the current user
     *
     * @return \Illuminate\Database\Eloquent\Relations\hasMany
     */
    public function images(): HasMany
    {
        /**
         *
         * On the Image model is an MorphTo relation
         * By using a hasMany relation:
         * where the imageable_type is filled in with the KmsClass
         * And the imageable_id is set as the foreign_id,
         * we can collect the images of the given model directly.
         *
         */
        return $this->hasMany(Image::class, 'imageable_id')
            ->where('imageable_type', '=', $this->class);
    }

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

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

        if($key == "parent_id") {
            if($this::find($this->id))
                return $this->getParentId();
        }

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