sant_id = $data['sant_id']; $this->vihar_id = $vihar_id; $this->start_date = $data['start_date']; } /** * Determine if the validation rule passes. * * @param string $attribute * @param mixed $value * @return bool */ public function passes($attribute, $value) { $santID = $this->sant_id; $numberOfPosts = Vihar::where('sant_id', $this->sant_id) // ->orWhere( function ($query) use ($santID) { // return $query->whereHas('viharThana', function ($subQuery) use ($santID) { // $subQuery->where('vihar_thanas.sant_id', $santID); // })->orWhere('vihars.sant_id', $santID); // }) ->where('id', '<>', $this->vihar_id) ->whereDate('start_date', $this->start_date) // ->whereDate('created_at', Carbon::today()) ->count(); if ($numberOfPosts >= 2) { return false; } else { return true; } } /** * Get the validation error message. * * @return string */ public function message() { return 'Only 2 Vihaar`s can be added for any sant in a day'; } }