File: D:/HostingSpaces/SBogers10/honger.komma.pro/app/KommaApp/PostAuthors/Models/PostAuthor.php
<?php
/**
*
*
* @author Komma <info@komma.pro>
* @copyright (c) 2012-2016, Komma
*/
namespace App\KommaApp\PostAuthors\Models;
use App\KommaApp\DisplayNameTrait;
use App\KommaApp\Images\Models\Image;
use App\KommaApp\Posts\Models\Post;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* Class Page
*
* @package App\KommaApp\Pages\Models
* @property int site_id
* @property int lft
* @property int rgt
* @property int tree
* @property-read \Carbon $date
* @property-read \Illuminate\Database\Eloquent\Collection|\App\KommaApp\Images\Models\Image[] $images
* @property-read \Illuminate\Database\Eloquent\Collection|\App\KommaApp\Languages\Models\Language[] $languages
* @property-read \Illuminate\Database\Eloquent\Collection|\App\KommaApp\Sites\Models\Site[] $sites
* @property \App\KommaApp\PostAuthors\Models\PostTranslation $translation
* @property-read \Illuminate\Database\Eloquent\Collection|\App\KommaApp\PostAuthors\Models\PostTranslation[] $translations
* @mixin \Eloquent
* @property int $id
* @property int $active
* @property \Carbon\Carbon|null $created_at
* @property \Carbon\Carbon|null $updated_at
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\PostAuthors\Models\PostAuthor whereActive($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\PostAuthors\Models\PostAuthor whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\PostAuthors\Models\PostAuthor whereDate($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\PostAuthors\Models\PostAuthor whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\KommaApp\PostAuthors\Models\PostAuthor whereUpdatedAt($value)
*/
class PostAuthor extends Model
{
use DisplayNameTrait;
protected $table = 'post_authors';
protected $class = PostAuthor::class;
/*
* Transient properties on Eloquent models
* These are not saved to database.
*/
public $thumbnail = false;
public $blocks = false;
protected $fillable = ['name', 'function'];
public function posts(): HasMany
{
return $this->hasMany(Post::class,'post_author_id');
}
/**
* 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);
}
}