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/wingssprayer.komma.pro/app/Employees/Models/Employee.php
<?php
/**
 *
 *
 * @author      Komma <info@komma.pro>
 * @copyright   (c) 2012-2016, Komma
 */

namespace App\Employees\Models;

use App\Components\Component\ComponentableInterface;
use App\Components\Component\ComponentableTrait;
use Illuminate\Support\Str;
use Komma\KMS\Documents\DocumentsTrait;
use Komma\KMS\Documents\Kms\DocumentableInterface;
use Komma\KMS\Core\Entities\DisplayNameInterface;
use Komma\KMS\Core\Entities\DisplayNameTrait;
use Komma\KMS\Globalization\Languages\Models\Language;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Komma\KMS\Core\Tree\NestedSets\Nodes\AbstractTranslatableTreeModel;
use Komma\KMS\Helpers\KommaHelpers;

/**
 * Class Employee
 *
 * @package App\Employees\Models
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Globalization\Languages\Models\Language[] $languages
 * @property-read \App\Employees\Models\EmployeeTranslation $translation
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Employees\Models\EmployeeTranslation[] $translations
 * @mixin \Eloquent
 * @property int $id
 * @property int $active
 * @property int|null $lft
 * @property int|null $rgt
 * @property int|null $tree
 * @property \Carbon\Carbon|null $created_at
 * @property \Carbon\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Employees\Models\Employee whereActive($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Employees\Models\Employee whereCodeName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Employees\Models\Employee whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Employees\Models\Employee whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Employees\Models\Employee whereLft($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Employees\Models\Employee whereRgt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Employees\Models\Employee whereSiteId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Employees\Models\Employee whereTree($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Employees\Models\Employee whereUpdatedAt($value)
 * @property-read \Illuminate\Database\Eloquent\Collection|\Komma\KMS\Documents\Models\Document[] $documents
 * @property-read \Illuminate\Database\Eloquent\Collection|\Komma\KMS\Documents\Models\Document[] $images
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Components\Component\Component[] $components
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Employees\Models\Employee newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Employees\Models\Employee newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Employees\Models\Employee query()
 * @property int|null $site_id
 * @property string|null $name
 * @property int $cta_person
 * @property-read int|null $documents_count
 * @property-read int|null $images_count
 * @property-read int|null $languages_count
 * @property-read \App\Site\Site|null $site
 * @property-read int|null $translations_count
 * @method static \Illuminate\Database\Eloquent\Builder|Employee whereCtaPerson($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Employee whereName($value)
 */
final class Employee extends AbstractTranslatableTreeModel implements DisplayNameInterface, DocumentableInterface
{
    use DocumentsTrait;
    use DisplayNameTrait;

    protected $class = Employee::class;

    protected $fillable = ['active', 'site_id', 'lft', 'rgt', 'tree', 'name'];

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

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

    public function __get($key)
    {
        if($key == "parent_id") {
            if($this::find($this->id))
                return $this->getParentId();
        }

        return parent::__get($key);
    }

    /**
     * @return string
     */
    public function getSidebarName():string
    {
        // If there is no name defined generate a generic name
        if(!$sidebarName = $this->getDisplayName()){
            return __('kms/employees.entity') . ' '.$this->id;
        }
        return $sidebarName;
    }
}