table = $table; $this->columns = $columns; } /** * Determine if the validation rule passes. * * @param mixed $attribute Not used. * @param mixed $value The value to compare. * @return boolean */ public function passes(mixed $attribute, mixed $value) { foreach ($this->columns as $column) { $result = DB::table($this->table) ->where($column, '!=', '') ->where($column, '!=', null) ->where($attribute, '=', '') ->exists(); if ($result !== null) { return false; } } return true; } /** * Get the validation error message. * * @return string */ public function message() { return 'The :attribute field is required if any of the following fields are not empty: ' . implode(', ', $this->columns); } }