<?php namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Log extends Model {

    protected $fillable = ['employee_id','guardian_id','date_log','in_out'];

    public function getDates(){
        return['created_at' , 'updated_at' , 'date_log'];
    }

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

    public function guardian(){
        return $this->belongsTo('App\Models\Guardian','guardian_id');
    }


    public function scopeFilterByMonth($query,$month){
        return $query->whereRaw('Month(date_log)='.$month);
    }
    public function scopeFilterByYear($query,$year){
        return $query->whereRaw('Year(date_log)='.$year);
    }
    public function scopeFilterByDay($query,$day){
        return $query->whereRaw('Day(date_log)='.$day);
    }
    public function scopeFilterByInterval($query,$hour,$inf,$sup){
        return $query->whereRaw('Hour(date_log)='.$hour.' And Minute(date_log) >= '.$inf.' And Minute(date_log) <= '.$sup);
    }
    public function scopeLogIn($query){
        return $query->where('in_out',true);
    }
    public function scopeLogOut($query){
        return $query->where('in_out',false);
    }


}
