File: D:/HostingSpaces/SBogers10/rentman2019.komma.pro/app/Komma/Crews/Models/Crew.php
<?php
/**
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2016, Komma
*/
namespace App\Komma\Crews\Models;
use App\Komma\Documents\DocumentsTrait;
use App\Komma\Documents\Kms\DocumentableInterface;
use App\Komma\Kms\Core\Entities\DisplayNameInterface;
use App\Komma\Kms\Core\Entities\DisplayNameTrait;
use App\Komma\Kms\Core\NestedSets\Nodes\AbstractTranslatableTreeModel;
use App\Komma\Languages\Models\Language;
use App\Komma\PricingLabels\Models\PricingLabel;
use App\Komma\Sites\HasSiteInterface;
use App\Komma\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\HasOne;
/**
* Class Page
*
* @property int site_id
* @property int lft
* @property int rgt
* @property int tree
* @property-read \Carbon $date
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Languages\Models\Language[] $languages
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Sites\Models\Site[] $sites
* @property-read \App\Komma\Crews\Models\CrewTranslation $translation
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Crews\Models\CrewTranslation[] $translations
* @mixin \Eloquent
* @property int $id
* @property int $active
* @property \Carbon\Carbon|null $created_at
* @property \Carbon\Carbon|null $crewd_at
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Crews\Models\Crew whereActive($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Crews\Models\Crew whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Crews\Models\Crew whereDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Crews\Models\Crew whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Crews\Models\Crew whereCrewdAt($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\Crews\Models\Crew newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Crews\Models\Crew newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Crews\Models\Crew query()
*/
class Crew extends AbstractTranslatableTreeModel implements HasSiteInterface, DocumentableInterface, DisplayNameInterface
{
use DocumentsTrait;
use DisplayNameTrait;
protected $table = 'crews';
protected $class = self::class;
protected $fillable = ['site_id', 'lft', 'rgt', 'tree', '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(CrewTranslation::class);
}
public function languages(): BelongsToMany
{
return $this->belongsToMany(Language::class, 'crew_translations')
->withPivot('name')
->withTimestamps();
}
/**
* Get the fallback translation model (English: 40).
*
* @throws \RuntimeException
*/
public function fallback_translation(): HasOne
{
// Note: Use magic number 40 as english translation
return $this->hasOne(CrewTranslation::class)->where('language_id', '=', 40);
}
/**
* @return BelongsToMany
*/
public function pricingLabels(): BelongsToMany
{
return $this->belongsToMany(PricingLabel::class, 'crew_pricing_labels');
}
/**
* Get the site for this this model
*
* @return belongsTo
*/
public function site(): BelongsTo
{
return $this->belongsTo(Site::class, 'site_id'); //Model must have site_id attribute
}
public function __get($key)
{
if ($key == 'parent_id') {
if ($this::find($this->id)) {
return $this->getParentId();
}
}
return parent::__get($key);
}
}