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

namespace App\Komma\Kms\Core\Entities;

use App\Komma\Kms\Core\AbstractTranslatableModel;

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 != '') {
            return $this->name;
        }
        // Else detect if the model is a translatableModel
        elseif (is_a($this, AbstractTranslatableModel::class)) {
            // Detect if the default language name isset else grab there is first other translation there is that has the name filled.
            if (isset($this->translation) && ! empty($this->translation->name)) {
                return $this->translation->name;
            } elseif (isset($this->translations) && $this->translations->count() != 0) {
                foreach ($this->translations as $translation) {
                    if (! empty($translation->name)) {
                        return $translation->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;
    }
}