File: D:/HostingSpaces/SBogers10/somerenslust.komma.pro/app/KommaApp/Schemes/Models/Scheme.php
<?php
/**
*
*
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2016, Komma
*/
namespace App\KommaApp\Schemes\Models;
use App\KommaApp\Images\Models\Image;
use App\KommaApp\Kms\Core\AbstractTranslatableModel;
use App\KommaApp\Kms\Core\NestedSets\Nodes\EloquentNode;
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 Scheme
* @package App\KommaApp\Schemes\Models
*
* @property int id
* @property int site_id
* @property int active
* @property string start_date
* @property string end_date
* @property string location
*/
class Scheme extends AbstractTranslatableModel
{
protected $table = 'schemes';
protected $class = Scheme::class;
/*
* Transient properties on Eloquent models
* These are not saved to database.
*/
public $thumbnail = false;
// public $parent_id;
protected $fillable = ['active', '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(SchemeTranslation::class);
}
public function languages(): BelongsToMany
{
return $this->belongsToMany(Language::class, 'scheme_translations')
->withPivot('slug', 'name', 'description')
->withTimestamps();
}
public function __get($key)
{
if($key == "title") {
if($this->translations()->first()) {
return $this->translations()->first()->name;
}
}
return parent::__get($key);
}
}