Black Friday: coupon FRIDAY24 for 40% off Yearly/Lifetime membership! Read more here

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:

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...

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 67 courses (1172 lessons, total 43 h 18 min)
  • 90 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord

Recent New Courses