Laravel v5.3.19 is now released
Published on by Eric L. Barnes
Laravel released v5.3.19 which includes a few small changes and improvements as well as a complete rewrite of the middleware sorting so that middleware calls with parameters now work properly.
PHP Artisan make:model
A new addition to Laravel is the ability to specify the creation of a resourceful controller when you are creating a new Model through Artisan. This means you can pass a -c
or --controller
flag to make:model:
php artisan make:model Post --controller
Laravel Image Dimensions Validation
New in Laravel v5.3 is the ability to validate image files to ensure they meet certain dimensions and through the validator this can be setup with a string format:
'avatar' => 'dimensions:min_width=100,min_height=200,ratio=3/2'
Now in v5.3.19 this can be specified through a fluent syntax similar to unique and exists validation rules:
Rule::dimensions()->minWidth(100)->minHeight(100)->ratio(3/2)
Laravel Validation in and not_in
The in
and not_in
validation received the ability to pass an array.
// Previousin:php,laravel,...// NewRule::in(['php','laravel'])
Then the same for not_in
// Previousnot_in:php,laravel,...// NewRule::notIn(['php', 'laravel'])
Either style is valid and the new object-based style parses down into the old way. So you are free to use whichever suits your app.
After Validation Hook
Now your controllers can have a new withValidator
method so you can easily call any hooks after validation:
protected function withValidator($validator){ $validator->after(function($validator) { if ($this->somethingElseIsInvalid()) { $validator->errors()->add('field', 'Something is wrong with this field!'); } });}
Previously you had to manually setup the $validator = Validator::make()
before you could use an after hook which meant you lost the ability to utilize the ValidatesRequests
trait.
Upgrading Laravel
To get this latest version all you need to do is run composer update
and you can find a complete list of changes in the changelog
Eric is the creator of Laravel News and has been covering Laravel since 2012.