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

namespace App\KommaApp\Services\Models;

use App\KommaApp\Kms\Core\NestedSets\Nodes\TranslatableEloquentNode;
use App\KommaApp\Languages\Models\Language;
use App\KommaApp\Sites\Models\Site;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;

/**
 * Class Service
 *
 * @package App\KommaApp\Services\Models
 * @property int id
 * @property int site_id
 * @property int active
 * @property string code_name
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\KommaApp\Languages\Models\Language[] $languages
 * @property-read \App\KommaApp\Sites\Models\Site $site
 * @property-read \App\KommaApp\Services\Models\ServiceTranslation $translation
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\KommaApp\Services\Models\ServiceTranslation[] $translations
 * @mixin \Eloquent
 */
class Service extends TranslatableEloquentNode
{
    protected $table = 'services';
    protected $class = Service::class;

    const FromUs = 0;
    const ForClient = 1;

    /*
    * Transient properties on Eloquent models
    * These are not saved to database.
    */
    public $thumbnail = false;
//    public $parent_id;


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

    public function site(): BelongsTo
    {
        return $this->belongsTo(Site::class);
    }

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

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

    public function __get($key)
    {
        if($key == "title") {
            if($this->translation) {
                return $this->translation->name;
            }
        }

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

        return parent::__get($key);
    }
}