class Unique implements Stringable (View source)

Traits

Properties

protected string $table

The table to run the query against.

from  DatabaseRule
protected string $column

The column to check on.

from  DatabaseRule
protected array $wheres

The extra where clauses for the query.

from  DatabaseRule
protected array $using

The array of custom query callbacks.

from  DatabaseRule
protected mixed $ignore

The ID that should be ignored.

protected string $idColumn

The name of the ID column.

Methods

$this|TWhenReturnType
when($value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

$this|TUnlessReturnType
unless($value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

void
__construct(string $table, string $column = 'NULL')

Create a new rule instance.

string
resolveTableName(string $table)

Resolves the name of the table from the given string.

$this
where(Closure|string $column, Arrayable|BackedEnum|Closure|array|string|int|bool|null $value = null)

Set a "where" constraint on the query.

$this
whereNot(string $column, Arrayable|BackedEnum|array|string $value)

Set a "where not" constraint on the query.

$this
whereNull(string $column)

Set a "where null" constraint on the query.

$this
whereNotNull(string $column)

Set a "where not null" constraint on the query.

$this
whereIn(string $column, Arrayable|BackedEnum|array $values)

Set a "where in" constraint on the query.

$this
whereNotIn(string $column, Arrayable|BackedEnum|array $values)

Set a "where not in" constraint on the query.

$this
withoutTrashed(string $deletedAtColumn = 'deleted_at')

Ignore soft deleted models during the existence check.

$this
onlyTrashed(string $deletedAtColumn = 'deleted_at')

Only include soft deleted models during the existence check.

$this
using(Closure $callback)

Register a custom query callback.

array
queryCallbacks()

Get the custom query callbacks for the rule.

string
formatWheres()

Format the where clauses.

$this
ignore(mixed $id, string|null $idColumn = null)

Ignore the given ID during the unique check.

$this
ignoreModel(Model $model, string|null $idColumn = null)

Ignore the given model during the unique check.

string
__toString()

Convert the rule to a validation string.

Details

$this|TWhenReturnType when($value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) truthy.

Parameters

$value
callable|null $callback
callable|null $default

Return Value

$this|TWhenReturnType

$this|TUnlessReturnType unless($value = null, callable|null $callback = null, callable|null $default = null)

Apply the callback if the given "value" is (or resolves to) falsy.

Parameters

$value
callable|null $callback
callable|null $default

Return Value

$this|TUnlessReturnType

void __construct(string $table, string $column = 'NULL')

Create a new rule instance.

Parameters

string $table
string $column

Return Value

void

string resolveTableName(string $table)

Resolves the name of the table from the given string.

Parameters

string $table

Return Value

string

$this where(Closure|string $column, Arrayable|BackedEnum|Closure|array|string|int|bool|null $value = null)

Set a "where" constraint on the query.

Parameters

Closure|string $column
Arrayable|BackedEnum|Closure|array|string|int|bool|null $value

Return Value

$this

$this whereNot(string $column, Arrayable|BackedEnum|array|string $value)

Set a "where not" constraint on the query.

Parameters

string $column
Arrayable|BackedEnum|array|string $value

Return Value

$this

$this whereNull(string $column)

Set a "where null" constraint on the query.

Parameters

string $column

Return Value

$this

$this whereNotNull(string $column)

Set a "where not null" constraint on the query.

Parameters

string $column

Return Value

$this

$this whereIn(string $column, Arrayable|BackedEnum|array $values)

Set a "where in" constraint on the query.

Parameters

string $column
Arrayable|BackedEnum|array $values

Return Value

$this

$this whereNotIn(string $column, Arrayable|BackedEnum|array $values)

Set a "where not in" constraint on the query.

Parameters

string $column
Arrayable|BackedEnum|array $values

Return Value

$this

$this withoutTrashed(string $deletedAtColumn = 'deleted_at')

Ignore soft deleted models during the existence check.

Parameters

string $deletedAtColumn

Return Value

$this

$this onlyTrashed(string $deletedAtColumn = 'deleted_at')

Only include soft deleted models during the existence check.

Parameters

string $deletedAtColumn

Return Value

$this

$this using(Closure $callback)

Register a custom query callback.

Parameters

Closure $callback

Return Value

$this

array queryCallbacks()

Get the custom query callbacks for the rule.

Return Value

array

protected string formatWheres()

Format the where clauses.

Return Value

string

$this ignore(mixed $id, string|null $idColumn = null)

Ignore the given ID during the unique check.

Parameters

mixed $id
string|null $idColumn

Return Value

$this

$this ignoreModel(Model $model, string|null $idColumn = null)

Ignore the given model during the unique check.

Parameters

Model $model
string|null $idColumn

Return Value

$this

string __toString()

Convert the rule to a validation string.

Return Value

string