File: D:/HostingSpaces/SBogers10/honger7.komma.pro/app/KommaApp/Cases/Models/CaseModel.php
<?php
/**
* Created by PhpStorm.
* User: mike
* Date: 18/05/17
* Time: 22:00
*/
namespace App\KommaApp\Cases\Models;
use Illuminate\Database\Eloquent\Model;
class CaseModel extends Model
{
protected $table = 'cases';
protected $kmsClass = 'KommaApp\\Cases\\Models\\CaseModel';
public function site()
{
return $this->belongsTo(\App\KommaApp\Sites\Models\Site::class);
}
public function translations()
{
return $this->hasMany(\App\KommaApp\Cases\Models\CaseTranslation::class, 'case_id');
}
public function translation()
{
// todo: dynamic language
return $this->hasOne(\App\KommaApp\Cases\Models\CaseTranslation::class, 'case_id')->where('language_id',104);
}
public function languages()
{
return $this->belongsToMany(\App\KommaApp\Languages\Models\Language::class, 'case_translations')
->withPivot('description')
->withTimestamps();
}
public function getParentId()
{
if ($this->getDepth() == 0) {
// Node is root node
return 0;
}
return $this->getParent()->id;
}
/**
* Get the images from the current page
*
* @return Collection
*/
public function images()
{
/**
*
* On the Image model is an MorphTo relation
* By using a hasMany relation:
* where the imageable_type is filled in with the KmsClass
* And the imageable_id is set as the foreign_id,
* we can collect the images of the given model directly.
*
*/
return $this->hasMany('\App\KommaApp\Images\Models\Image', 'imageable_id')
->where('imageable_type', '=', $this->kmsClass)
->orderBy('id');
}
}