File: D:/HostingSpaces/Eurotools/euro-tools.nl/app/KommaApp/CustomerService/Models/CustomerService.php
<?php
/**
*
*
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2016, Komma
*/
namespace App\KommaApp\CustomerService\Models;
use App\KommaApp\Images\Models\Image;
use App\KommaApp\Kms\Core\AbstractTranslatableModel;
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;
/**
* Class CustomerService
*
* @package App\KommaApp\CustomerService\Models
* @property int site_id
* @property int $id
* @property int $active
* @property string|null $code_name
* @property \Carbon\Carbon|null $created_at
* @property \Carbon\Carbon|null $updated_at
* @property \App\KommaApp\CustomerService\Models\CustomerServiceTranslation $translation
* @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 \Illuminate\Database\Eloquent\Collection|\App\KommaApp\CustomerService\Models\CustomerServiceTranslation[] $translations
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\CustomerService\Models\CustomerService whereActive($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\CustomerService\Models\CustomerService whereCodeName($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\CustomerService\Models\CustomerService whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\CustomerService\Models\CustomerService whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\CustomerService\Models\CustomerService whereUpdatedAt($value)
* @mixin \Eloquent
*/
class CustomerService extends AbstractTranslatableModel implements HasImagesInterface
{
protected $table = 'customer_services';
protected $class = CustomerService::class;
/*
* Transient properties on Eloquent models
* These are not saved to database.
*/
public $thumbnail = false;
// public $parent_id;
protected $fillable = ['active', 'code_name'];
/**
* Gets the translation models for this model
*
* @return HasMany that resolves to AbstractTranslationModel instances
*/
public function translations(): HasMany
{
return $this->hasMany(CustomerServiceTranslation::class);
}
public function languages(): BelongsToMany
{
return $this->belongsToMany(Language::class, 'customer_services_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);
}
public function __get($key)
{
if($key == "title") {
if($this->translation) {
return $this->translation->title;
}
}
return parent::__get($key);
}
}