pub struct Unique { /* private fields */ }Expand description
The builder that Rule::unique and
Rule::unique_in return. Use it to choose a row to skip and to
filter the rows the rule checks. It converts into a Rule.
use laravel::db::col;
use laravel::validation::{DatabaseRules, Rule, Rules};
let rules = Rules::new().field(
"email",
[Rule::unique_in::<String>("users", "email")
.ignore_user()
.filter(col("deleted_at").is_null())],
);Implementations§
Source§impl Unique
impl Unique
Sourcepub fn ignore<'a>(self, id: impl Into<Value<'a>>) -> Self
pub fn ignore<'a>(self, id: impl Into<Value<'a>>) -> Self
Skips the row with this ID, such as the team a handler is updating. A null ID, such as
None::<i64>, skips no row.
use laravel::validation::{DatabaseRules, Rule};
let rule = Rule::unique_in::<String>("teams", "name").ignore(team_id);Sourcepub fn ignore_user(self) -> Self
pub fn ignore_user(self) -> Self
Skips the logged-in user’s row, so a user can keep their own email address. For a guest, the rule skips no row.
When the session guard finds users with model::Users, the rule
finds the row by the user model’s key column. Otherwise, it finds the row by id.
Sourcepub fn ignore_route<P: Model + RouteModel>(
self,
parameter: impl Into<String>,
) -> Self
pub fn ignore_route<P: Model + RouteModel>( self, parameter: impl Into<String>, ) -> Self
Skips the row of the P that this route parameter names, such as team in
/teams/{team}, by P’s key column.
The rule finds the model the same way route model binding does, once per request. So it works when the route finds the model by another column, such as a slug.
use laravel::validation::{DatabaseRules, Rule};
let rule = Rule::unique_in::<String>("teams", "name").ignore_route::<Team>("team");Sourcepub fn ignore_column(self, column: impl Into<String>) -> Self
pub fn ignore_column(self, column: impl Into<String>) -> Self
Finds the skipped row by this column, such as uuid or slug, instead of id or the user
model’s key column. The rule compares the column with the ID as given.
Sourcepub fn filter(self, condition: impl IntoCondition) -> Self
pub fn filter(self, condition: impl IntoCondition) -> Self
Checks only the rows that meet condition, such as the rows of one team. Like
Builder::filter, each call adds a condition that must also
hold. A None condition adds nothing.
use laravel::db::col;
use laravel::validation::{DatabaseRules, Rule};
let rule = Rule::unique_in::<String>("members", "email").filter(col("team_id").eq(team_id));Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Unique
impl !UnwindSafe for Unique
impl Forget for Unique
impl Freeze for Uniquewhere
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
&'static str: Freeze,
PhantomData<Condition>: Freeze,
PhantomData<for<'r> fn(&'r Request) -> Pin<Box<dyn Future<Output = Result<Option<Condition>, Error>> + Send + 'r>>>: Freeze,
&'static Location<'static>: Freeze,
String: Freeze,
&'static [u8]: Freeze,
Vec<u8>: Freeze,
&'static BigDecimal: Freeze,
BigDecimal: Freeze,
PhantomData<Value>: Freeze,
PhantomData<usize>: Freeze,
PhantomData<Bucket<String, Value>>: Freeze,
*const ArcInner<Error> is !null: Freeze,
PhantomData<ArcInner<Error>>: Freeze,
&'static [f32]: Freeze,
Vec<f32>: Freeze,
impl Move for Unique
impl Send for Uniquewhere
RawVecInner: Send,
&'static str: Send,
BoxRaw<Condition>: Send,
String: Send,
&'static [u8]: Send,
Vec<u8>: Send,
&'static BigDecimal: Send,
BigDecimal: Send,
RawTable<usize>: Send,
Arc<Error>: Send,
&'static [f32]: Send,
Vec<f32>: Send,
BoxRaw<Expr>: Send,
Arc<Select>: Send,
BoxRaw<Search>: Send,
Arc<[f32]>: Send,
BoxRaw<str>: Send,
Arc<str>: Send,
Arc<String>: Send,
Arc<dyn Any + Sync + Send>: Send,
&'static Location<'static>: Send,
impl Sync for Uniquewhere
RawVecInner: Sync,
BoxRaw<Condition>: Sync,
String: Sync,
Vec<u8>: Sync,
BigDecimal: Sync,
RawTable<usize>: Sync,
Arc<Error>: Sync,
Vec<f32>: Sync,
BoxRaw<Expr>: Sync,
Arc<Select>: Sync,
BoxRaw<Search>: Sync,
Arc<[f32]>: Sync,
BoxRaw<str>: Sync,
Arc<str>: Sync,
Arc<String>: Sync,
Arc<dyn Any + Sync + Send>: Sync,
Location<'static>: Sync,
impl Unpin for Uniquewhere
*const u8 is !null: Unpin,
&'static str: Unpin,
Box<Condition>: Unpin,
String: Unpin,
&'static [u8]: Unpin,
Vec<u8>: Unpin,
&'static BigDecimal: Unpin,
BigDecimal: Unpin,
Arc<Error>: Unpin,
&'static [f32]: Unpin,
Vec<f32>: Unpin,
Box<Expr>: Unpin,
Arc<Select>: Unpin,
Box<Search>: Unpin,
Arc<[f32]>: Unpin,
Box<str>: Unpin,
Arc<str>: Unpin,
Arc<String>: Unpin,
Arc<dyn Any + Sync + Send>: Unpin,
&'static Location<'static>: Unpin,
impl UnsafeUnpin for Uniquewhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
&'static str: UnsafeUnpin,
PhantomData<Condition>: UnsafeUnpin,
PhantomData<for<'r> fn(&'r Request) -> Pin<Box<dyn Future<Output = Result<Option<Condition>, Error>> + Send + 'r>>>: UnsafeUnpin,
&'static Location<'static>: UnsafeUnpin,
String: UnsafeUnpin,
&'static [u8]: UnsafeUnpin,
Vec<u8>: UnsafeUnpin,
&'static BigDecimal: UnsafeUnpin,
BigDecimal: UnsafeUnpin,
PhantomData<Value>: UnsafeUnpin,
PhantomData<usize>: UnsafeUnpin,
PhantomData<Bucket<String, Value>>: UnsafeUnpin,
*const ArcInner<Error> is !null: UnsafeUnpin,
PhantomData<ArcInner<Error>>: UnsafeUnpin,
&'static [f32]: UnsafeUnpin,
Vec<f32>: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<K> ForeignKey<K> for K
impl<K> ForeignKey<K> for K
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more