File: D:/HostingSpaces/SBogers10/beat-the-barn.komma.nl/app/Testimonials/Models/Testimonial.php
<?php
namespace App\Testimonials\Models;
use Komma\KMS\Components\Component\ComponentableInterface;
use Komma\KMS\Components\Component\ComponentableTrait;
use Komma\KMS\Documents\DocumentsTrait;
use Komma\KMS\Documents\Kms\DocumentableInterface;
use Komma\KMS\Core\AbstractTranslatableModel;
use Komma\KMS\Core\Entities\DisplayNameInterface;
use Komma\KMS\Core\Entities\DisplayNameTrait;
use Komma\KMS\Globalization\Languages\Models\Language;
use Komma\KMS\Sites\HasSiteInterface;
use App\Site\Site;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Str;
/**
* 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 \Illuminate\Database\Eloquent\Collection|\App\Languages\Models\Language[] $languages
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Site\Site[] $sites
* @property-read \App\Testimonials\Models\TestimonialTranslation $translation
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Testimonials\Models\TestimonialTranslation[] $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\Testimonials\Models\Testimonial whereActive($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Testimonials\Models\Testimonial whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Testimonials\Models\Testimonial whereDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Testimonials\Models\Testimonial whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Testimonials\Models\Testimonial 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\Testimonials\Models\Testimonial newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Testimonials\Models\Testimonial newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Testimonials\Models\Testimonial query()
*/
final class Testimonial extends AbstractTranslatableModel implements ComponentableInterface, DocumentableInterface, DisplayNameInterface
{
use DocumentsTrait;
use DisplayNameTrait;
use ComponentableTrait;
protected $table = 'testimonials';
protected $class = Testimonial::class;
protected $fillable = ['active', 'name', 'url'];
/**
* Gets the translation models for this model
*
* @return HasMany that resolves to AbstractTranslationModel instances
*/
public function translations(): HasMany
{
return $this->hasMany(TestimonialTranslation::class);
}
public function languages(): BelongsToMany
{
return $this->belongsToMany(Language::class, 'testimonial_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;
// Else detect if the model is a translatableModel
if(is_a($this, AbstractTranslatableModel::class)){
if(isset($this->translations) && $this->translations->count() != 0) $modelTranslation = $this->translations->where('language_id', '=','104')->first();
if(isset($modelTranslation) && isset($modelTranslation->title) && $modelTranslation->title != '')
return $modelTranslation->title;
}
return null;
}
/**
* Get the name for the sidebar
*
* @return string
*/
public function getSidebarName():string
{
// If there is no name defined generate a generic name
if(!$sideBarName = $this->getDisplayName()){
$sideBarName = trans( 'KMS::'.Str::camel($this->table).'.entity') . ' ' . $this->id;
}
return $sideBarName;
}
}