<?php

namespace App;

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

class Speciality extends Model
{
    use SoftDeletes;

    public static function withDescription($id = null)
    {
        $specialities = self::join('speciality_descriptions as sd', 'sd.speciality_id', 'specialities.id')
            ->where('sd.language_id', currentLanguage()->id);

        if ($id){
            $specialities->where('specialities.id', $id);
        }

        $specialities->select(['specialities.*', 'sd.name']);

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