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/SBogers84/zuiderbos.nl/workbench/komma/kms/src/Komma/Kms/Jobs/Models/Job.php
<?php
/**
 * @author      Pascal Lemmen <pascal@komma.pro>
 * @copyright   (c) 2012-2016, Komma Mediadesign
 */

namespace Komma\Kms\Jobs\Models;

use Komma\Kms\Core\NestedSets\Nodes\EloquentNode as NestedSetNode;

class Job extends NestedSetNode
{
    protected $table = 'jobs';
    protected $kmsClass = 'Komma\\Kms\\Jobs\\Models\\Job';

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

    public function getParentId()
    {
        if($this->getDepth() == 0){
            // Node is root node
            return 0;
        }
        return $this->getParent()->id;
    }

    public function shop()
    {
        return $this->belongsTo('Komma\Kms\Shops\Shop');
    }

    public function translations()
    {
        return $this->hasMany('Komma\Kms\Jobs\Models\JobTranslation');
    }

    public function languages()
    {
        return $this->belongsToMany('Komma\Kms\Languages\Language', 'job_translations')
            ->withPivot('slug')
            ->withTimestamps();
    }


    public function schools(){
        return $this->belongsToMany('Komma\Kms\Schools\School', 'jobs_school', 'job_id', 'school_id');
    }

    /**
     * Get the images from the current reference
     *
     * @return Collection
     */
    public function images()
    {
        /**
         *
         * On the Image model is an MorphTo relation
         * By using a hasMany relation:
         * where the imageble_type is filled in with the KmsClass
         * And the imageble_id is set as the foreign_id,
         * we can collect the images of the given model directly.
         *
         */
        return $this->hasMany('Komma\Kms\Images\Models\Image', 'imageble_id')
            ->where('imageble_type', '=', $this->kmsClass)
            ->orderBy('sort_order');
    }

}