File: D:/HostingSpaces/SBogers10/rentman.komma.pro/app/Komma/Cases/Models/CaseClass.php
<?php
/**
* Short description for the file.
*
* @author Komma <support@komma.pro>
* @copyright (c) 2012-2015, Komma Mediadesign
*/
namespace Komma\Cases\Models;
use Illuminate\Database\Eloquent\Collection;
class CaseClass extends \Komma\Kms\Cases\Models\CaseClass
{
public $kmsClass = 'Komma\\Kms\\Cases\\Models\\CaseClass';
/**
* Get the translation for the current language
*
* @return Collection
*/
public function translation()
{
/**
* On the translation model is an BelongsTo relation.
* We want to collect the current translation.
* Therefore we create a hasOne relation
* Where we will select the case_translation,
* Join on the languages table
* And set the current Locale as the languages.iso_2
*
*/
$translation = $this->hasOne('Komma\Cases\Models\CaseTranslation', 'case_id')
//We only need the translation
->select('case_translations.*')
//Join the languages
->join('languages', 'languages.id', '=', 'case_translations.language_id')
//Get only the language with the correct lang
->where('languages.iso_2', '=', \App::getLocale());
return $translation;
}
/**
* 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 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');
}
}