<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Review extends Model
{
    //use soft delete
    use SoftDeletes;

    protected $fillable = [
        'image','rate'
    ];


    public static function withDescription($review_id = null)
    {
        $query = self::orderByDesc('reviews.id')->join('review_descriptions as sd', 'sd.review_id', 'reviews.id')
            ->where('sd.language_id', currentLanguage()->id)
            ->select(['reviews.created_at', 'sd.*']);
        if ($review_id){
            $query->where('reviews.id', $review_id);
        }

        $query->select([
            'reviews.*',
            'sd.name',
            'sd.description',
        ]);
        return $query;
    }
}
