<?php

namespace App;

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

class Consulting extends Model
{
    use SoftDeletes;

    public static function withDescription($id = null)
    {
        $consultings = self::join('consulting_descriptions as cd', 'cd.consulting_id', 'consultings.id')
            ->where('cd.language_id', currentLanguage()->id);

            if($id){
                $consultings->where('consultings.id', $id);
            }
        $consultings->select(['consultings.*', 'cd.name']);

        return $id ? $consultings->first() : $consultings->cursor();
    }
}
