Moderate.php 812 B

123456789101112131415
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class Moderate extends Model
  5. {
  6. protected $casts = [ 'user_id' => 'integer', 'post_type' => 'string', 'post_id' => 'integer' ];
  7. public function user() { return $this->hasMany(User::class, 'id', 'user_id'); }
  8. public function comment() { return $this->hasMany(Comment::class, 'id', 'post_id'); }
  9. public function post() { return $this->hasMany(Post::class, 'id', 'post_id'); }
  10. public function scopeAllPost($query, $id){ return $query->where('post_type', "App\Models\Post")->where('post_id', $id)->with('user')->orderBy('created_at', 'desc')->get(); }
  11. public function scopeAllComment($query, $id){ return $query->where('post_type', "App\Models\Comment")->where('post_id', $id)->with('user')->orderBy('created_at', 'desc')->get(); }
  12. }