DEV Community

Morcos Gad
Morcos Gad

Posted on • Updated on

New Things Added - Laravel 9.1 and 9.2 Released

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

  • Disabled Directive

This PR provides the use of the common HTML directive disabled through a shorthand syntax via a Blade directive (true | false) https://github.com/laravel/framework/pull/40900

<button type="submit" @disabled($errors->isNotEmpty())>Submit</button>
Enter fullscreen mode Exit fullscreen mode
  • Support for passing array as the second parameter for the group method

https://github.com/laravel/framework/pull/40945

Route::middleware('web')
   ->namespace($this->namespace)
      ->group([
         base_path('routes/account/web.php'),
         base_path('routes/account/staff.php')
       ]);
Enter fullscreen mode Exit fullscreen mode
  • firstOr() function to BelongsToMany relation

https://github.com/laravel/framework/pull/40828

$post = $user->posts()->firstOr(function () {
    // return default post...
});
Enter fullscreen mode Exit fullscreen mode
  • filtering of route:list by domain

https://github.com/laravel/framework/pull/40970

php artisan route:list --domain=example.com
Enter fullscreen mode Exit fullscreen mode
  • doesntContain to higher order proxies

https://github.com/laravel/framework/pull/41034

User::latest()->take(5)->get()->doesntContain('type','admin'); //true
Enter fullscreen mode Exit fullscreen mode
  • Attribute Make Method

static constructor method to the Eloquent Attribute class, which provides convenience as follows
https://github.com/laravel/framework/pull/41014

// Using the new keyword
return (new Attribute(
    get: fn ($value) => strtoupper($value),
    set: fn ($value) => strtoupper($value)
))->withoutObjectCaching();

// The new make() static constructor method
return Attribute::with(
    get: fn ($value) => strtoupper($value),
    set: fn ($value) => strtoupper($value)
)->withoutObjectCaching();
Enter fullscreen mode Exit fullscreen mode
  • Array keyBy Method

Arr::keyBy() method which works like the collection keyBy() method
https://github.com/laravel/framework/pull/41029

$array = [
    ['id' => '123', 'data' => 'abc', 'device' => 'laptop'],
    ['id' => '345', 'data' => 'def', 'device' => 'tablet'],
    ['id' => '345', 'data' => 'hgi', 'device' => 'smartphone'],
];

Arr::keyBy($array, 'id');
/*
[
    '123' => ['id' => '123', 'data' => 'abc', 'device' => 'laptop'],
    '345' => ['id' => '345', 'data' => 'hgi', 'device' => 'smartphone']
    // The second element of an original array is overwritten by the last element because of the same id
]
*/
Enter fullscreen mode Exit fullscreen mode
  • Expects Output to Contain Test Assertion

expectsOutputToContain test method to assert that artisan commands contain a substring of output
https://github.com/laravel/framework/pull/40984

$this->artisan('Hello World')->expectsOutputToContain('Hello');
Enter fullscreen mode Exit fullscreen mode
  • Replace Laravel CORS package

https://github.com/laravel/laravel/pull/5825

  • String "Between First" Method

betweenFirst() method which gets the smallest possible portion of a string between two given values
https://github.com/laravel/framework/pull/41144

Str::betweenFirst('[a]ab[b]', '[', ']'); // a
Str::betweenFirst('foofoobar', 'foo', 'bar'); // foo
Str::betweenFirst('hannah', 'ha', 'ah'); // nn
Str::betweenFirst('dddabcddd', 'a', 'c')); // b
Enter fullscreen mode Exit fullscreen mode
  • Allow Specifying a Custom Message for Rule Objects

way to specify a custom error message when validating with a Rule object. With this update, you can provide a custom message to the messages array
https://github.com/laravel/framework/pull/41145

$request->validate(
    [
        'foo' => [new Example]
    ],
    [
        Example::class => 'My custom message goes here!'
    ]
);
Enter fullscreen mode Exit fullscreen mode
  • Add X-Headers when using Mail::alwaysTo

https://github.com/laravel/framework/pull/41101

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://www.youtube.com/watch?v=tRpWTYTUCfM
Source :- https://laravel-news.com/laravel-9-2-0
Source :- https://www.youtube.com/watch?v=TcZJrO6FWug

Discussion (0)