File: D:/HostingSpaces/SBogers10/somerenslust.komma.pro/app/KommaApp/Sponsors/Models/Sponsor.php
<?php
/**
*
*
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2016, Komma
*/
namespace App\KommaApp\Sponsors\Models;
use App\KommaApp\Images\Models\Image;
use App\KommaApp\Kms\Core\NestedSets\Nodes\EloquentNode;
use App\KommaApp\Sites\Models\Site;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* Class Page
* @package App\KommaApp\Pages\Models
*
* @property int id
* @property int site_id
* @property int active
* @property string code_name
* @property int lft
* @property int rgt
* @property int tree
*/
class Sponsor extends Model
{
protected $table = 'sponsors';
protected $class = Sponsor::class;
/*
* Transient properties on Eloquent models
* These are not saved to database.
*/
public $thumbnail = false;
// public $parent_id;
protected $fillable = ['active', 'site_id', 'code_name', 'url', 'name'];
public function site(): BelongsTo
{
return $this->belongsTo(Site::class);
}
/**
* Get the images from the current user
*
* @return \Illuminate\Database\Eloquent\Relations\hasMany
*/
public function images(): HasMany
{
/**
*
* 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(Image::class, 'imageable_id')
->where('imageable_type', '=', $this->class);
}
public function __get($key)
{
if($key == "title") {
return $this->name;
}
return parent::__get($key);
}
}