<?php

namespace App\Models;

use Illuminate\Support\Facades\Auth;
use App\Scopes\OrganisationScope;

use Illuminate\Database\Eloquent\Model;

class Warning extends Model
{
    protected $fillable = [
        'warning_to',
        'warning_by',
        'subject',
        'warning_date',
        'description',
        'created_by',
        'organisation_id',
    ];


    public function employee()
    {
        return $this->hasOne('App\Models\Employee', 'id', 'employee_id')->first();
    }

    public function warningTo($warningto)
    {
        return Employee::where('id',$warningto)->first();
    }
    public function warningBy($warningby)
    {
        return Employee::where('id',$warningby)->first();
    }

    protected static function booted()
    {
        static::addGlobalScope(new OrganisationScope);

        static::creating(function ($model) {
            if (Auth::check()) {
                $model->organisation_id = Auth::user()->organisation_id;
            }
        });
    }

}