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/slenders.komma.pro/app/Komma/MonthlyMustHaves/Models/MonthlyMustHave.php
<?php
namespace App\Komma\MonthlyMustHaves\Models;

use App\Komma\Categories\CategorizableInterface;
use App\Komma\Categories\Models\Category;
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 App\Komma\Users\Models\KmsUser;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
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 \App\Komma\Globalization\Languages\Models\Language[] $languages
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Sites\Models\Site[] $sites
 * @property-read \App\Komma\MonthlyMustHaves\Models\MonthlyMustHaveTranslation $translation
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\MonthlyMustHaves\Models\MonthlyMustHaveTranslation[] $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\MonthlyMustHaves\Models\MonthlyMustHave whereActive($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\MonthlyMustHaves\Models\MonthlyMustHave whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\MonthlyMustHaves\Models\MonthlyMustHave whereDate($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\MonthlyMustHaves\Models\MonthlyMustHave whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\MonthlyMustHaves\Models\MonthlyMustHave 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\MonthlyMustHaves\Models\MonthlyMustHave newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\MonthlyMustHaves\Models\MonthlyMustHave newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\MonthlyMustHaves\Models\MonthlyMustHave query()
 */
final class MonthlyMustHave extends AbstractTranslatableModel implements HasSitesInterface, DocumentableInterface, DisplayNameInterface, CategorizableInterface
{
    use DocumentsTrait;
    use DisplayNameTrait;

    protected $table = 'monthly_must_haves';
    protected $class = MonthlyMustHave::class;

    protected $fillable = ['active', 'date', 'price'];

    protected $dates = ['date'];

    public function category() : MorphToMany
    {
        return $this->morphToMany(Category::class,'categorable');
    }

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

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

    /**
     * Get the site or sites for this model
     *
     * @return BelongsToMany
     */
    public function sites(): BelongsToMany
    {
        return $this->belongsToMany(Site::class);
    }

//    public function author(): HasOne
//    {
//        return $this->hasOne(User::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;
    }
}