Comment.php 828 B

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