File: D:/HostingSpaces/SBogers10/rentman2019.komma.pro/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;
}
}