<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;

class Leave extends Model {
	protected $table = 'leave';
	protected $fillable = [
			'child_id',
			'class_id',
			'class_date',
			'reason'
	];
	public function getChildCount($parent_id) {
		return $this->where ( 'parent_id', $parent_id )->count ();
	}

	public function parent() {
		return $this->hasOne ( 'App\Model\User', 'id', 'parent_id' );
	}
	/**
	 * @Description:获取孩子请的假
	 *
	 */
	public static function checkIsLeave($childId,$classId,$classDate){
		$where['child_id']=$childId;
		$where['class_id']=$classId;
		$where['class_date']=$classDate;
		
		$count=Leave::where($where)->count();
		return $count;
	}
	public function child(){
		return $this->belongsTo('App\Models\Children', 'child_id', 'id');
	}
}
