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/SBogers95/rentman.io/app/Komma/PricingLabels/Models/PricingLabel.php
<?php
/**
 * @author      Komma <info@komma.pro>
 * @copyright   (c) 2012-2016, Komma
 */

namespace App\Komma\PricingLabels\Models;

use App\Helpers\KommaHelpers;
use App\Komma\Kms\Core\AbstractTranslatableModel;
use App\Komma\Kms\Core\Entities\DisplayNameInterface;
use App\Komma\Kms\Core\Entities\DisplayNameTrait;
use App\Komma\Languages\Models\Language;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;

/**
 * Class Page
 *
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Languages\Models\Language[] $languages
 * @property-read \App\Komma\PricingLabels\Models\PricingLabelTranslation $translation
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\PricingLabels\Models\PricingLabelTranslation[] $translations
 * @mixin \Eloquent
 * @property int $id
 * @property \Carbon\Carbon|null $created_at
 * @property \Carbon\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\PricingLabels\Models\PricingLabel whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\PricingLabels\Models\PricingLabel whereDate($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\PricingLabels\Models\PricingLabel whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\PricingLabels\Models\PricingLabel whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\PricingLabels\Models\PricingLabel newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\PricingLabels\Models\PricingLabel newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\PricingLabels\Models\PricingLabel query()
 */
class PricingLabel extends AbstractTranslatableModel implements DisplayNameInterface
{
    use DisplayNameTrait;

    protected $table = 'pricing_labels';

    protected $class = self::class;

    protected $fillable = ['code_name'];

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

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

    /**
     * @return string
     */
    public function getSidebarName():string
    {
        // If there is no name defined generate a generic name
        if (! $sidebarName = $this->getDisplayName()) {
            $translationKey = \Str::camel($this->getTable()).'.entity';

            $translation = __('shop/'.$translationKey);
            if ($translation !== 'shop/'.$translationKey) {
                $sidebarName = $translation;
            } else {
                $sidebarName = __('kms/'.$translationKey);
            }

            $sidebarName .= ' '.$this->id;
        } else {
            $sidebarName = KommaHelpers::str_limit_full_word($sidebarName, 55);
            $sidebarName = '<sub>'.$this->code_name.'</sub><br/>'.$sidebarName;
        }

        return $sidebarName;
    }
}