<?php

namespace App;

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

class Staff extends Model
{
    use SoftDeletes;

    protected $table = 'staffs';

    protected $fillable = [
        'image',
        'email',
        'phone',
        'linkedin',
        'twitter',
    ];

    public static function withDescription($id = null)
    {
        $language_id = currentLanguage()->id;
        $staffs = self::join('staff_descriptions as sd', 'sd.staff_id', 'staffs.id')
            ->where('sd.language_id', $language_id);
        if ($id){
            $staffs->where('staffs.id', $id);
        }
        $staffs->select([
            'staffs.*',
            'sd.name',
            'sd.description',
            'sd.job_title',
            'sd.brief',
            'sd.practical_experience',
            'sd.training_courses',
            'sd.skills',
            'sd.practical_experience_title',
            'sd.training_courses_title',
            'sd.skills_title',
        ]);

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