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/farmfun.komma.pro/app/Komma/Posts/Models/Post.php
<?php

namespace App\Komma\Posts\Models;

use App\Helpers\KommaHelpers;
use App\Komma\Documents\DocumentsTrait;
use App\Komma\Documents\Kms\DocumentableInterface;
use App\Komma\Globalization\Language;
use App\Komma\Kms\Core\AbstractTranslatableModel;
use App\Komma\Kms\Core\Entities\DisplayNameInterface;
use App\Komma\Kms\Core\Entities\DisplayNameTrait;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Str;

/**
 * Class Post
 *
 * @property int site_id
 * @property int lft
 * @property int rgt
 * @property int tree
 * @property-read \Carbon $date
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Sites\Models\Site[] $sites
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Posts\Models\PostTranslation[] $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\Posts\Models\Post whereActive($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Posts\Models\Post whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Posts\Models\Post whereDate($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Posts\Models\Post whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Posts\Models\Post 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\Posts\Models\Post newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Posts\Models\Post newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Posts\Models\Post query()
 */
class Post extends AbstractTranslatableModel implements DocumentableInterface, DisplayNameInterface
{
    use DocumentsTrait;
    use DisplayNameTrait;

    protected $class = self::class;

    protected $fillable = ['date', 'created_at', 'updated_at'];

    protected $dates = ['date', 'created_at', 'updated_at'];

    /**
     * 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();
    }

    /**
     * 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;
        }

        if (strlen($sideBarName) > 50) {
            $sideBarName = KommaHelpers::str_limit_full_word($sideBarName, 45);
        }

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

        return $sideBarName;
    }
}