File: D:/HostingSpaces/SBogers10/werkenbij.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\Buttons\Models\Button;
use App\Komma\Documents\DocumentsTrait;
use App\Komma\Documents\Kms\DocumentableInterface;
use App\Komma\Components\Component\ComponentableInterface;
use App\Komma\Components\Component\ComponentableTrait;
use App\Komma\Kms\Core\Entities\DisplayNameInterface;
use App\Komma\Kms\Core\Entities\DisplayNameTrait;
use App\Komma\Kms\Core\Tree\NestedSets\Nodes\AbstractTranslatableTreeModel;
use App\Komma\Globalization\Languages\Models\Language;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* Class Page
*
* @package App\Komma\Pages\Models
* @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 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\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 \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 = Page::class;
protected $fillable = ['active', 'site_id', 'lft', 'rgt', 'tree', 'code_name', 'inNav'];
/**
* 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();
}
/**
* @return BelongsToMany
*/
public function discoverPages(): BelongsToMany
{
return $this->belongsToMany(Page::class, 'page_discover_pages', 'page_id', 'discover_page_id');
}
/**
* @return BelongsTo
*/
public function callToActionButton(): BelongsTo
{
return $this->belongsTo(Button::class, 'cta_button_id');
}
/**
* @param string $key
* @return int|mixed
*/
public function __get($key)
{
if($key == "parent_id") {
if($this::find($this->id))
return $this->getParentId();
}
return parent::__get($key);
}
}