File: D:/HostingSpaces/SBogers95/rentman.io/app/Komma/PricingProducts/Models/PricingProduct.php
<?php
/**
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2016, Komma
*/
namespace App\Komma\PricingProducts\Models;
use App\Komma\Documents\DocumentsTrait;
use App\Komma\Documents\Kms\DocumentableInterface;
use App\Komma\Kms\Core\Entities\DisplayNameInterface;
use App\Komma\Kms\Core\Entities\DisplayNameTrait;
use App\Komma\Kms\Core\NestedSets\Nodes\AbstractTranslatableTreeModel;
use App\Komma\Languages\Models\Language;
use App\Komma\Sites\HasSiteInterface;
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\Database\Eloquent\Relations\HasOne;
/**
* Class Page
*
* @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\PricingProducts\Models\PricingProductTranslation $translation
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Komma\PricingProducts\Models\PricingProductTranslation[] $translations
* @mixin \Eloquent
* @property int $id
* @property int $active
* @property \Carbon\Carbon|null $created_at
* @property \Carbon\Carbon|null $pricingproductd_at
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\PricingProducts\Models\PricingProduct whereActive($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\PricingProducts\Models\PricingProduct whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\PricingProducts\Models\PricingProduct whereDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\PricingProducts\Models\PricingProduct whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\PricingProducts\Models\PricingProduct wherePricingProductdAt($value)
* @property-read \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\PricingProducts\Models\PricingProduct newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\PricingProducts\Models\PricingProduct newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Komma\PricingProducts\Models\PricingProduct query()
*/
class PricingProduct extends AbstractTranslatableTreeModel implements HasSiteInterface, DocumentableInterface, DisplayNameInterface
{
use DocumentsTrait;
use DisplayNameTrait;
protected $table = 'pricing_products';
protected $class = self::class;
protected $fillable = ['site_id', 'lft', 'rgt', 'tree', 'created_at', 'updated_at'];
/**
* Gets the translation models for this model
*
* @return HasMany that resolves to AbstractTranslationModel instances
*/
public function translations(): HasMany
{
return $this->hasMany(PricingProductTranslation::class);
}
public function languages(): BelongsToMany
{
return $this->belongsToMany(Language::class, 'pricing_product_translations')
->withPivot('name')
->withTimestamps();
}
/**
* Get the fallback translation model (English: 40).
*
* @throws \RuntimeException
*/
public function fallback_translation(): HasOne
{
// Note: Use magic number 40 as english translation
return $this->hasOne(PricingProductTranslation::class)->where('language_id', '=', 40);
}
/**
* Get the site for this this model
*
* @return belongsTo
*/
public function site(): BelongsTo
{
return $this->belongsTo(Site::class, 'site_id'); //Model must have site_id attribute
}
public function __get($key)
{
if ($key == 'parent_id') {
if ($this::find($this->id)) {
return $this->getParentId();
}
}
return parent::__get($key);
}
}