File: D:/HostingSpaces/Lacom/lacom.nl/app/KommaApp/References/Models/Reference.php
<?php
/**
*
*
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2016, Komma
*/
namespace App\KommaApp\References\Models;
use App\KommaApp\Images\Models\Image;
use App\KommaApp\Kms\Core\AbstractTranslatableModel;
use App\KommaApp\Kms\Core\HasImagesInterface;
use App\KommaApp\Languages\Models\Language;
use App\KommaApp\Pages\Models\Page;
use App\KommaApp\Segments\Models\Segment;
use App\KommaApp\Sites\Models\Site;
use App\KommaApp\Specialisms\Models\Specialism;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphOne;
use Illuminate\Database\Eloquent\Relations\MorphTo;
/**
* Class Reference
* @package App\KommaApp\References\Models
*
* @property int id
* @property int site_id
* @property int active
* @property string code_name
* @property string name
* @property string company
* @property string linkedin
* @property int type
*/
class Reference extends AbstractTranslatableModel implements HasImagesInterface
{
protected $table = 'references';
protected $class = Reference::class;
const REFERENCE_TYPE_CUSTOMER = 1;
const REFERENCE_TYPE_EMPLOYEE = 2;
/*
* Transient properties on Eloquent models
* These are not saved to database.
*/
public $thumbnail = false;
// public $parent_id;
protected $fillable = ['active', 'site_id', 'name', 'code_name', 'company', 'linkedin', 'type'];
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(ReferenceTranslation::class);
}
public function languages(): BelongsToMany
{
return $this->belongsToMany(Language::class, 'reference_translations')
->withPivot('slug', 'name', 'description')
->withTimestamps();
}
public function pages()
{
return $this->morphedByMany(Page::class, 'referenceable');
}
public function segments()
{
return $this->morphedByMany(Segment::class, 'referenceable');
}
public function specialisms()
{
return $this->morphedByMany(Specialism::class, 'referenceable');
}
/**
* 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);
}
public function __get($key)
{
if ($key == "title") {
return $this->name;
}
return parent::__get($key);
}
}