File: D:/HostingSpaces/stafa/stafa.nl/app/Komma/Locations/Models/Location.php
<?php
/**
*
*
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2016, Komma
*/
namespace App\Komma\Locations\Models;
use App\Komma\Components\Component\ComponentableInterface;
use App\Komma\Components\Component\ComponentableTrait;
use App\Komma\Departments\Models\Department;
use App\Komma\Documents\DocumentsTrait;
use App\Komma\Documents\Kms\DocumentableInterface;
use App\Komma\Globalization\Languages\Models\Language;
use App\Komma\Kms\Core\AbstractTranslatableModel;
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\Sites\HasSitesInterface;
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 Location
*
* @package App\Komma\Locations\Models
* @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\Locations\Models\LocationTranslation $translation
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Locations\Models\LocationTranslation[] $translations
* @mixin \Eloquent
* @property int $id
* @property int $active
* @property string $name
* @property \Carbon\Carbon|null $created_at
* @property \Carbon\Carbon|null $updated_at
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Locations\Models\Location whereActive($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Locations\Models\Location whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Locations\Models\Location whereDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Locations\Models\Location whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Locations\Models\Location 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
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Locations\Models\Location newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Locations\Models\Location newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Locations\Models\Location query()
*/
final class Location extends AbstractTranslatableTreeModel implements HasSitesInterface, DocumentableInterface, DisplayNameInterface
{
use DocumentsTrait;
use DisplayNameTrait;
protected $table = 'locations';
protected $class = Location::class;
protected $fillable = ['active', 'lft', 'rgt', 'tree', 'site_id'];
/**
* Gets the translation models for this model
*
* @return HasMany that resolves to AbstractTranslationModel instances
*/
public function translations(): HasMany
{
return $this->hasMany(LocationTranslation::class);
}
public function languages(): BelongsToMany
{
return $this->belongsToMany(Language::class, 'location_translations')
->withPivot('slug', 'name', 'description')
->withTimestamps();
}
/**
* Get the site or sites for this model
*
* @return BelongsToMany
*/
public function sites(): BelongsToMany
{
return $this->belongsToMany(Site::class);
}
public function __get($key)
{
if($key == "parent_id") {
if($this::find($this->id))
return $this->getParentId();
}
return parent::__get($key);
}
}