DEV Community

Morcos Gad
Morcos Gad

Posted on

New undot() and reverse() methods in Laravel 8

Let's get started quickly and take some examples of these great methods
There’s now a helper method called reverse() in Illuminate\Support\Str and Illuminate\Support\Stringable using which it’s now convenient to reverse strings.

use Illuminate\Support\Str;

echo Str::reverse('raBooF');
// FooBar

echo Str::of('FooBar')->reverse();
// raBooF
Enter fullscreen mode Exit fullscreen mode

And next, the framework has got the counterpart of the Arr::dot() method called undot().

use Illuminate\Support\Arr;

$productInfo = [
    'products.desk.price' => 100
];

$unflattenedProductInfo = Arr::undot($productInfo);

/* 
[
    'products' => [
        'desk' => [
            'price' => 100
        ]
    ]
];
*/
Enter fullscreen mode Exit fullscreen mode

I hope you enjoyed the code.

Discussion (0)