replaceMatches('/(?<=)/m', '') ->toString(); } /** * Asserts that the field is unique. * * @param array|string|int|float|bool|null $value * * @throws \Illuminate\Validation\ValidationException If the field is not unique. */ public static function assertFieldIsUnique( string $table, string $field, string | int | float | bool | null | array $value, null | int | string $id = null, \Closure | string | null $query = null ): void { if (! $query) { Validator::make([$field => $value], [ (string) str_replace('.', '\.', $field) => Rule::unique($table, $field)->ignore($id), ], [ (string) str_replace('.', '\.', "{$field}.unique") => trans( 'validation.unique', ['attribute' => $field] ), ])->validate(); return; } Validator::make([$field => $value], [ $field => Rule::unique($table)->where($query)->ignore($id), ], [ $field . '.unique' => trans( 'validation.unique', ['attribute' => $field] ), ])->validate(); } }