File: D:/HostingSpaces/SBogers10/somerenslust.komma.pro/app/KommaApp/Akkoords/Models/Akkoord.php
<?php
/**
*
*
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2016, Komma
*/
namespace App\KommaApp\Akkoords\Models;
use App\KommaApp\Kms\Core\AbstractTranslatableModel;
use App\KommaApp\Languages\Models\Language;
use App\KommaApp\Sites\Models\Site;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* Class Akkoord
* @package App\KommaApp\Akkoords\Models
*
* @property int id
* @property int site_id
* @property int active
* @property string date
*/
class Akkoord extends AbstractTranslatableModel
{
protected $table = 'akkoords';
protected $class = Akkoord::class;
/*
* Transient properties on Eloquent models
* These are not saved to database.
*/
public $thumbnail = false;
// public $parent_id;
protected $fillable = ['active', 'date', 'site_id'];
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(AkkoordTranslation::class);
}
public function languages(): BelongsToMany
{
return $this->belongsToMany(Language::class, 'akkoord_translations')
->withPivot( 'name')
->withTimestamps();
}
public function __get($key)
{
if($key == "title") {
if($this->translations()->first()) {
return $this->translations()->first()->name;
}
}
return parent::__get($key);
}
}