Review.php 801 B

1234567891011121314151617
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class Review extends Model
  5. {
  6. protected $casts = [ 'game_id' => 'integer', 'author_id' => 'integer', 'text' => 'string', 'stars' => 'integer' ];
  7. public function comment() { return $this->morphMany(Comment::class, 'post'); }
  8. public function author() { return $this->belongsTo(Critic::class); }
  9. public function game() { return $this->belongsTo(Game::class); }
  10. public function scopeWithSp($query){
  11. return $query->join('critics', 'reviews.author_id', 'critics.id')->join('specializations', 'critics.specialization_id', 'specializations.id')
  12. ->select('reviews.*', 'critics.name as author', 'critics.id as author_id', 'specializations.title as specialization_title')->orderBy('created_at', 'desc');
  13. }
  14. }