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