Three new features in Laravel 5.2.22
Two days ago Taylor Otwell released a new minor version of Laravel framework – 5.2.22. Along with some small fixes, there are a few new functions, let’s look into them.
A lot of people think that Laravel is a creature by Taylor Otwell only, but in fact there are more people contributing to the framework now – one of them is Mohamed Said from Egypt, who shared the news about new features in 5.2.22, so here we go:
-
Validate array distinct
New rule to validate if array has only different values:
['products.*.product_id' => 'distinct']
);
Validator::make(
['products' =>
['product_id' => 1, 'quantity' => 5],
['product_id' => 1, 'quantity' => 99],
['product_id' => 2, 'quantity' => 1],
],
['products.*.product_id' => 'distinct']
);
This validation will fail, cause there are multiple products with same product_id value.
-
fullUrlWithQuery()
If you ever need to form a URL with adding some GET parameters to the end, now you can take a current request and append an array to it. Here’s an example – let’s say your current URL is domain.com/catalog and you want new URL to be domain.com/catalog?category=1&order=price:
$request->fullUrlWithQuery(['category' => '1', 'order' => 'price']);
Link:
This post is submitted by our members. Submit a new post.
Tags: Tutorials Laravel 5 Laravel 5.2