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

namespace App\Komma\Services\Models;

use App\Komma\Documents\DocumentsTrait;
use App\Komma\Documents\Kms\DocumentableInterface;
use App\Komma\Globalization\Languages\Models\Language;
use App\Komma\Kms\Core\Entities\DisplayNameInterface;
use App\Komma\Kms\Core\Entities\DisplayNameTrait;
use App\Komma\Kms\Core\Tree\NestedSets\Nodes\AbstractTranslatableTreeModel;
use App\Komma\Sites\HasSiteInterface;
use App\Komma\Sites\HasSitesInterface;
use App\Komma\Sites\Models\Site;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Str;

/**
 * Class Page
 *
 * @package App\Komma\Pages\Models
 * @property int site_id
 * @property int lft
 * @property int rgt
 * @property int tree
 * @property-read \Carbon $date
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Languages\Models\Language[] $languages
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Sites\Models\Site[] $sites
 * @property-read \App\Komma\Services\Models\ServiceTranslation $translation
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Services\Models\ServiceTranslation[] $translations
 * @mixin \Eloquent
 * @property int $id
 * @property int $active
 * @property \Carbon\Carbon|null $created_at
 * @property \Carbon\Carbon|null $updated_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Services\Models\Service whereActive($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Services\Models\Service whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Services\Models\Service whereDate($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Services\Models\Service whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Services\Models\Service whereUpdatedAt($value)
 * @property \Illuminate\Database\Eloquent\Collection|\App\Komma\Documents\Models\Document[] $documents
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\Documents\Models\Document[] $images
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Services\Models\Service newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Services\Models\Service newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\Services\Models\Service query()
 */
class Service extends AbstractTranslatableTreeModel implements HasSiteInterface, DocumentableInterface, DisplayNameInterface
{
    use DocumentsTrait;
    use DisplayNameTrait;

    protected $table = 'services';
    protected $class = Service::class;

    protected $fillable = ['active', 'site_id'];

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

    /**
     * Get the site or sites for this model
     *
     * @return BelongsTo
     */
    public function sites(): BelongsTo
    {
        return $this->belongsTo(Site::class);
    }

    /**
     * Get the name for the sidebar
     *
     * @return string
     */
    public function getSidebarName():string
    {
        // If there is no name defined generate a generic name
        if(!$sideBarName = $this->getDisplayName()){
            $sideBarName = trans( 'kms/'.Str::camel($this->table).'.entity') . ' ' . $this->id;
        }

        return $sideBarName;
    }
}