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:
1. Validate array distinct
New rule to validate if array has only different values:
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.
2. 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']);
3. Blade: continue and break
Good old loop conditions com directly to Blade: now if you have @foreach, you can stop the loop or continue it based on a certain condition:
@foreach ($products as $product)
@continue($product->category_id == 999)
{{ $product->name }}: {{ $product->price }}
@break($product->price >= 199)
@endforeach
As I mentioned, there are more tweaks and small features in new 5.2.22 for those who like to use the new versions or keen to update their projects as soon as the updates come up. Have fun playing!
No comments or questions yet...