DEV Community

Morcos Gad
Morcos Gad

Posted on • Updated on

New Things Added - Laravel 8.81 Released

Let's get started quickly I found new things in Laravel 8.81 Released I wanted to share with you.

  • Stringable Scan Method

Here we find it in php https://www.php.net/manual/en/function.sscanf.php https://www.w3schools.com/php/func_string_sscanf.asp and this feature is available now in laravel

$this->assertSame(
    [123456],
    $this->stringable('SN/123456')
         ->scan('SN/%d')
         ->toArray()
);

$this->assertSame(
    ['Otwell', 'Taylor'],
    $this->stringable('Otwell, Taylor')
         ->scan('%[^,],%s')
         ->toArray()
);

$this->assertSame(
    ['filename', 'jpg'],
    $this->stringable('filename.jpg')
         ->scan('%[^.].%s')
         ->toArray()
);
Enter fullscreen mode Exit fullscreen mode
  • Disable Caching in Attribute Accessors

disable caching for attributes being accessed via the new Attribute class. You can use the new API in a few ways

public function finish(): Attribute
{
    return Attribute::getWithoutCaching(
        fn () => $this->start->addSeconds($this->duration)
    );
}

// or

public function finish(): Attribute
{
    return Attribute::get(
        fn () => $this->start->addSeconds($this->duration)
    )->disableObjectCaching();
}
Enter fullscreen mode Exit fullscreen mode
  • Get or Put Collection Method

getOrPut method to collections which simplifies the use-case where you either want to get an existing key or put the value if it doesn't exist and return the value

// Still valid,
if ($this->collection->has($key) === false) {
    $this->collection->put($key, $this->create($data));
}

return $this->collection->get($key);

// Using the `getOrPut()` method with closure
return $this->collection->getOrPut($key, fn () => $this->create($data));

// Or pass a fixed value
return $this->collection->getOrPut($key, $value);
Enter fullscreen mode Exit fullscreen mode

I hope you enjoyed with me and to learn more about this release visit the sources and search more. I adore you who search for everything new.
Source :- https://laravel-news.com/laravel-8-81-0
Source :- https://www.youtube.com/watch?v=vuSZPsMePHc

Top comments (0)