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/Kms/Core/Entities/DisplayNameTrait.php
<?php

namespace App\Komma\Kms\Core\Entities;

use App\Komma\Kms\Core\AbstractTranslatableModel;
use Illuminate\Support\Str;

trait DisplayNameTrait
{
    /**
     * Get the name of this model by model or translation model
     *
     * @return null|string
     */
    public function getDisplayName():?string
    {
        // If it is a new model the section name will filled by model.section.new
        if (! $this->exists) {
            return null;
        }

        // First try to get the name of the model
//        if(isset($this->name) && $this->name != '') { //When you do an isset like this, you cannot use a magic method like in orders to set and return the name of a model
        if (isset($this->name) && $this->name != '') {
            return $this->name;
        }
        // Else detect if the model is a translatableModel
        elseif (is_a($this, AbstractTranslatableModel::class)) {
            if (isset($this->translations) && $this->translations->count() != 0) {
                $modelTranslation = $this->translations->first();
            }

            if (isset($modelTranslation) && isset($modelTranslation->name) && $modelTranslation->name != '') {
                return $modelTranslation->name;
            }
        }

        return null;
    }

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

        return $sidebarName;
    }
}