File: D:/HostingSpaces/SBogers33/bbec.nl/workbench/komma/kms/src/Komma/Kms/Blocks/Models/Block.php
<?php
/**
* @author Komma <support@komma.pro>
* @copyright (c) 2012-2016, Komma Mediadesign
*/
namespace Komma\Kms\Blocks\Models;
use Illuminate\Database\Eloquent\Model;
class Block extends Model
{
protected $table = 'blocks';
protected $fillable = ['active', 'shop_id', 'code_name', 'navigation_label', 'type'];
public function shop()
{
return $this->belongsTo('Komma\Kms\Shops\Shop');
}
public function translations()
{
return $this->hasMany('Komma\Kms\Blocks\Models\BlockTranslation');
}
public function languages()
{
return $this->belongsToMany('Komma\Kms\Languages\Language', 'block_translations')
->withPivot('slug', 'name', 'description')
->withTimestamps();
}
public function kmsTranslation()
{
/**
* 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 page_translation,
* Join on the languages table
* And set the current Locale as the languages.iso_2
*
*/
return $this->hasOne('Komma\Kms\Blocks\Models\BlockTranslation')
//We only need the translation
->select('block_translations.*')
->where('block_translations.language_id', '=', \Config::get('kms::main.defaultLanguageId'));
}
}