HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/shop.komma.nl/app/Posts/Models/Post.php
<?php
namespace App\Posts\Models;

use App\Users\SiteUser;
use Komma\KMS\Documents\DocumentsTrait;
use Komma\KMS\Documents\Kms\DocumentableInterface;
use Komma\KMS\Globalization\Languages\Models\Language;
use Komma\KMS\Core\AbstractTranslatableModel;
use Komma\KMS\Core\Entities\DisplayNameInterface;
use Komma\KMS\Core\Entities\DisplayNameTrait;
use Komma\KMS\Helpers\KommaHelpers;
use Komma\KMS\Sites\HasSiteInterface;
use Komma\KMS\Sites\HasSitesInterface;
use Komma\KMS\Sites\Models\Site;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Support\Carbon;
use Illuminate\Support\Str;
use Komma\KMS\Sites\SitesTrait;
use Komma\KMS\Sites\SiteTrait;

/**
 * App\Posts\Models\Post
 *
 * @property int $id
 * @property int $author_id
 * @property int $active
 * @property Carbon|null $date
 * @property Carbon|null $created_at
 * @property Carbon|null $updated_at
 * @property-read SiteUser|null $author
 * @property-read \Illuminate\Database\Eloquent\Collection|\Komma\KMS\Documents\Models\Document[] $documents
 * @property-read int|null $documents_count
 * @property-read \Illuminate\Database\Eloquent\Collection|\Komma\KMS\Documents\Models\Document[] $images
 * @property-read int|null $images_count
 * @property-read \Illuminate\Database\Eloquent\Collection|Language[] $languages
 * @property-read int|null $languages_count
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Site\Site[] $sites
 * @property-read int|null $sites_count
 * @property-read \App\Posts\Models\PostTranslation|null $translation
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Posts\Models\PostTranslation[] $translations
 * @property-read int|null $translations_count
 * @method static \Illuminate\Database\Eloquent\Builder|Post newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Post newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Post query()
 * @method static \Illuminate\Database\Eloquent\Builder|Post whereActive($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Post whereAuthorId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Post whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Post whereDate($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Post whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Post whereUpdatedAt($value)
 * @mixin \Eloquent
 */
final class Post extends AbstractTranslatableModel implements HasSitesInterface, DocumentableInterface, DisplayNameInterface
{
    use DocumentsTrait;
    use DisplayNameTrait;
    use SitesTrait;

    protected $table = 'posts';
    protected $class = Post::class;

    protected $fillable = ['active', 'date', 'site_id', 'author_id'];

    protected $dates = ['date'];

    /**
     * Gets the translation models for this model
     *
     * @return HasMany that resolves to AbstractTranslationModel instances
     */
    public function translations(): HasMany
    {
        return $this->hasMany(PostTranslation::class);
    }

    public function languages(): BelongsToMany
    {
        return $this->belongsToMany(Language::class, 'post_translations')
            ->withPivot('slug', 'name', 'description')
            ->withTimestamps();
    }

    public function author(): HasOne
    {
        return $this->hasOne(SiteUser::class);
    }

    /**
     * Get the name for the sidebar
     *q
     * @return string
     */
    public function getSidebarName():string
    {
        // If there is no name defined generate a generic name
        if(!$sidebarName = $this->getDisplayName()){
            $translationKey = Str::plural(KommaHelpers::getShortNameFromClass($this, true)).'.entity';

            $translation = __('KMS::'.$translationKey);
            if($translation !== 'KMS::'.$translationKey) $sidebarName = $translation;
            else $sidebarName = __('KMS::'.$translationKey);

            $sidebarName .= ' '.$this->id;
        }

        $sidebarName .= '<br/><sub>' . $this->date->format('d-m-Y') . '</sub>';

        return $sidebarName;
    }
}