File: D:/HostingSpaces/SBogers10/ste.komma.pro/app/Trainings/Models/Training.php
<?php
namespace App\Trainings\Models;
use App\SteLanguages\Models\SteLanguage;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Str;
use Komma\KMS\Core\AbstractTranslatableModel;
use Komma\KMS\Globalization\Languages\Models\Language;
use Komma\KMS\Core\Entities\DisplayNameInterface;
use Komma\KMS\Core\Entities\DisplayNameTrait;
use Komma\KMS\Helpers\KommaHelpers;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Carbon;
/**
* Class Page
*
* @package App\Pages\Models
* @property int site_id
* @property int lft
* @property int rgt
* @property int tree
* @property-read Carbon $date
* @property-read \App\Globalization\Languages\Models\Language[] $languages
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Sites\Models\Site $site
* @property-read \App\Trainings\Models\TrainingTranslation $translation
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Trainings\Models\TrainingTranslation[] $translations
* @mixin \Eloquent
* @property int $id
* @property int $active
* @property \Carbon\Carbon|null $created_at
* @property \Carbon\Carbon|null $updated_at
* @method static \Illuminate\Database\Eloquent\Builder|\App\Trainings\Models\Training whereActive($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Trainings\Models\Training whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Trainings\Models\Training whereDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Trainings\Models\Training whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Trainings\Models\Training whereUpdatedAt($value)
* @property-read \Illuminate\Database\Eloquent\Collection|\Komma\KMS\Documents\Models\Document[] $documents
* @property-read \Illuminate\Database\Eloquent\Collection|\Komma\KMS\Documents\Models\Document[] $images
* @method static \Illuminate\Database\Eloquent\Builder|\App\Trainings\Models\Training newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Trainings\Models\Training newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Trainings\Models\Training query()
*/
final class Training extends AbstractTranslatableModel implements DisplayNameInterface
{
use DisplayNameTrait;
protected $fillable = [
'c4_id',
'ste_language_id',
];
public array $translatableKeys = [
'training_type',
'lessons_each_week'
];
/**
* Gets the translation models for this model
*
* @return HasMany that resolves to AbstractTranslationModel instances
*/
public function translations(): HasMany
{
return $this->hasMany(TrainingTranslation::class);
}
public function languages(): BelongsToMany
{
return $this->belongsToMany(Language::class, 'training_translations')
->withPivot('slug', 'name', 'description')
->withTimestamps();
}
/**
* Get the name of this model by model or translation model
*
* @return null|string
*/
public function getDisplayName():?string
{
// If it is a new model the section name will filled by model.section.new
if(!$this->exists) return null;
// First try to get the name of the model
// if(isset($this->name) && $this->name != '') { //When you do an isset like this, you cannot use a magic method like in orders to set and return the name of a model
if(isset($this->c4_id) && $this->c4_id != '') {
return $this->c4_id;
}
return null;
}
}