File: D:/HostingSpaces/SBogers10/stafa.komma.pro/app/Komma/Events/Models/Event.php
<?php
namespace App\Komma\Events\Models;
use App\Komma\Documents\DocumentsTrait;
use App\Komma\Documents\Kms\DocumentableInterface;
use App\Komma\Globalization\Languages\Models\Language;
use App\Komma\Kms\Core\AbstractTranslatableModel;
use App\Komma\Kms\Core\Entities\DisplayNameInterface;
use App\Komma\Kms\Core\Entities\DisplayNameTrait;
use App\Komma\Sites\HasSitesInterface;
use App\Komma\Sites\Models\Site;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Carbon;
use Illuminate\Support\Str;
/**
* Class Page
*
* @package App\Komma\Pages\Models
* @property int site_id
* @property int lft
* @property int rgt
* @property int tree
* @property-read Carbon $date
* @property-read Carbon $end_date
* @property-read \App\Komma\Globalization\Languages\Models\Language[] $languages
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Sites\Models\Site[] $sites
* @property-read \App\Komma\Events\Models\EventTranslation $translation
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Events\Models\EventTranslation[] $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\Komma\Events\Models\Event whereActive($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Events\Models\Event whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Events\Models\Event whereDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Events\Models\Event whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Events\Models\Event whereUpdatedAt($value)
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Documents\Models\Document[] $documents
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Documents\Models\Document[] $images
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Events\Models\Event newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Events\Models\Event newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Events\Models\Event query()
*/
final class Event extends AbstractTranslatableModel implements HasSitesInterface, DocumentableInterface, DisplayNameInterface
{
use DocumentsTrait;
use DisplayNameTrait;
protected $table = 'events';
protected $class = Event::class;
protected $fillable = ['active', 'date', 'end_date', 'site_id', 'author_id'];
protected $dates = ['date', 'end_date'];
/**
* Gets the translation models for this model
*
* @return HasMany that resolves to AbstractTranslationModel instances
*/
public function translations(): HasMany
{
return $this->hasMany(EventTranslation::class);
}
public function languages(): BelongsToMany
{
return $this->belongsToMany(Language::class, 'event_translations')
->withPivot('slug', 'name', 'location')
->withTimestamps();
}
/**
* Get the site or sites for this model
*
* @return BelongsToMany
*/
public function sites() : BelongsToMany
{
return $this->belongsToMany(Site::class);
}
/**
* 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;
}
//$sideBarName .= '<br/><sub>' . $this->date->format('d-m-Y') . '</sub>';
return $sideBarName;
}
}