app/Post.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Prettus\Repository\Contracts\Transformable;
use Prettus\Repository\Traits\TransformableTrait;
class Post extends Model implements Transformable
{
use TransformableTrait;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'posts';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['title', 'slug', 'excerpt', 'content', 'image', 'author_id'];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = [];
/**
* Get the user record associated with the Post.
*/
public function author()
{
return $this->belongsTo(User::class);
}
/**
* Get all of the tags for the post.
*/
public function tags()
{
return $this->morphToMany(Tag::class, 'taggable');
}
}