pub struct Validator { /* private fields */ }Expand description
A set of fields, their rules, and the values to run them against.
Implementations§
Source§impl Validator
impl Validator
Sourcepub fn new(input: impl Into<Input>) -> Self
pub fn new(input: impl Into<Input>) -> Self
Validate a bag of values — a JSON body, a form, or an Input built by hand.
Sourcepub fn from_request(request: &mut Request) -> Self
pub fn from_request(request: &mut Request) -> Self
Validate a request, remembering whether the client wants JSON back so the failure response can be negotiated later, when the request is gone.
Sourcepub fn rule(self, field: impl Into<String>, rules: impl IntoRules) -> Self
pub fn rule(self, field: impl Into<String>, rules: impl IntoRules) -> Self
Add one field’s rules, as a Laravel string or as a built rule set.
Sourcepub fn rules(self, specs: &[(&str, &str)]) -> Self
pub fn rules(self, specs: &[(&str, &str)]) -> Self
Add every field at once: .rules(&[("email", "required|email")]).
Sourcepub fn message(self, key: impl Into<String>, message: impl Into<String>) -> Self
pub fn message(self, key: impl Into<String>, message: impl Into<String>) -> Self
Override one message. The key is "field.rule" or just "rule".
Sourcepub fn attribute(
self,
field: impl Into<String>,
label: impl Into<String>,
) -> Self
pub fn attribute( self, field: impl Into<String>, label: impl Into<String>, ) -> Self
Rename a field for display: .attribute("dob", "date of birth").
Sourcepub fn with_messages(self, messages: Messages) -> Self
pub fn with_messages(self, messages: Messages) -> Self
Replace the whole message bag, for an application that keeps its own.
Sourcepub fn with_json(self, wants_json: bool) -> Self
pub fn with_json(self, wants_json: bool) -> Self
Force the failure response to be JSON (or not), overriding what the request negotiated.
pub fn input(&self) -> &Input
pub fn passes(&self) -> bool
pub fn fails(&self) -> bool
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Validator
impl RefUnwindSafe for Validator
impl Send for Validator
impl Sync for Validator
impl Unpin for Validator
impl UnsafeUnpin for Validator
impl UnwindSafe for Validator
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
Mutably borrows from an owned value. Read more