For example, you may wish to require a given field only if another field has a greater value than 100.
Or, you may need two fields to have a given value only when another field is present.
trait which provides a convenient method to validate incoming HTTP request with a variety of powerful validation rules.
As mentioned previously, Laravel will automatically redirect the user back to their previous location.
In addition, all of the validation errors will automatically be flashed to the session.
Again, notice that we did not have to explicitly bind the error messages to the view in our Forcing A Unique Rule To Ignore A Given ID: Sometimes, you may wish to ignore a given ID during the unique check.
For example, consider an "update profile" screen that includes the user's name, e-mail address, and location.
First, let's assume we have the following routes defined in our method accepts an incoming HTTP request and a set of validation rules.
If the validation rules pass, your code will keep executing normally; however, if validation fails, an exception will be thrown and the proper error response will automatically be sent back to the user.Of course, you will want to verify that the e-mail address is unique.However, if the user only changes the name field and not the e-mail field, you do not want a validation error to be thrown because the user is already the owner of the e-mail address.In the case of a traditional HTTP request, a redirect response will be generated, while a JSON response will be sent for AJAX requests. Again, if the validation fails, the proper response will automatically be generated.If the validation passes, our controller will continue executing normally.If you are HTML-escaping correctly, these characters are perfectly fine, and unless your business rules says otherwise may be quite valid to include in a field—just as both characters are valid for me to type in this comment box for SO.