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