'integer', 'post_type' => 'string', 'post_id' => 'integer' ]; public function user() { return $this->hasMany(User::class, 'id', 'user_id'); } public function comment() { return $this->hasMany(Comment::class, 'id', 'post_id'); } public function post() { return $this->hasMany(Post::class, 'id', 'post_id'); } public function scopeAllPost($query, $id){ return $query->where('post_type', "App\Models\Post")->where('post_id', $id)->with('user')->orderBy('created_at', 'desc')->get(); } public function scopeAllComment($query, $id){ return $query->where('post_type', "App\Models\Comment")->where('post_id', $id)->with('user')->orderBy('created_at', 'desc')->get(); } }