laravel-validation
Laravel 5 how to validate route parameters?
For Laravel < 5.5: The way for this is overriding all() method for CheckTokenServerRequest like so: public function all() { $data = parent::all(); $data[‘token’] = $this->route(‘token’); return $data; } EDIT For Laravel >= 5.5: Above solution works in Laravel < 5.5. If you want to use it in Laravel 5.5 or above, you should use: … Read more
Laravel validation: exists with additional column condition – custom validation rule
From Laravel 5.3+ you can add a custom where clause to the exists and unique rules. Here is my scenario: I have an email verification table and I want to ensure that a passed machine code and activation code exist on the same row. Be sure to use Illuminate\Validation\Rule; $activationCode = $request->activation_code; $rules = [ … Read more
How to use the request route parameter in Laravel 5 form request?
That’s very simple, just use the route() method. Assuming your route parameter is called id: public function authorize(){ $id = $this->route(‘id’); }
Laravel 5.3 Validation Fails when Variables are Null
Add nullable rule: ‘firstName’ => ‘string|max:255|nullable’, ‘lastName’ => ‘string|max:255|nullable’ The field under validation may be null. This is particularly useful when validating primitive such as strings and integers that can contain null values.
How add Custom Validation Rules when using Form Request Validation in Laravel 5
While the above answer is correct, in a lot of cases you might want to create a custom validation only for a certain form request. You can leverage laravel FormRequest and use dependency injection to extend the validation factory. I think this solution is much simpler than creating a service provider. Here is how it … Read more
How to validate time in laravel
Use date_format rule validation date_format:H:i From docs date_format:format The field under validation must match the format defined according to the date_parse_from_format PHP function.
Laravel check for unique rule without itself in update
This forces to ignore specific id: ’email’ => ‘unique:table,email_column_to_check,id_to_ignore’ replace segments table, email_column_to_check, id_to_ignore in above example You could check it here http://laravel.com/docs/4.2/validation#rule-unique
validating a numeric input’s length in laravel 5
In fact you don’t need to use digits_between rule. You can use digits rule so according to documentation it will be enough to use: $rules = [ ‘national-id’ => ‘required|digits:10’ ]; without numeric rule because digits rule also verify if given value is numeric.