id = $attributes['id']; $this->user_pad_id = $attributes['user_pad_id']; $this->tarefa_id = $attributes['tarefa_id']; $this->type = $attributes['type']; $this->weekday = $attributes['weekday']; $this->start_time = $attributes['start_time']; $this->end_time = $attributes['end_time']; } /** * Determine if the validation rule passes. * * @param string $attribute * @param mixed $value * @return bool */ public function passes($attribute, $value) { $start_time = "{$this->start_time}:00"; $end_time = "{$this->end_time}:00"; $taskTimeQuery = TaskTime::whereUserPadId($this->user_pad_id) ->whereWeekday($this->weekday) ->where( function($query) use ($start_time, $end_time) { $query->whereBetween('start_time', [$start_time, $end_time]); $query->orWhereBetween('end_time', [$start_time, $end_time]); } ); if(isset($this->id)) { $taskTimeQuery->where('id', '!=', $this->id); } $this->taskTime = $taskTimeQuery->first(); return !$taskTimeQuery->exists(); } /** * Get the validation error message. * * @return string */ public function message() { return "Não é possivel utilizar o horário, ele está sendo preenchido por \"{$this->taskTime->getCode()} : {$this->taskTime->getName()}\" !"; } }