New Things Added - Laravel 9.1 and 9.2 Released
Tags: php, laravel, webdev, programming
Published: 2022-03-02 18:13:56

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
```php
<button type="submit" @disabled($errors->isNotEmpty())>Submit</button>
```

- Support for passing array as the second parameter for the group method
 
https://github.com/laravel/framework/pull/40945

```php
Route::middleware('web')
   ->namespace($this->namespace)
      ->group([
         base_path('routes/account/web.php'),
         base_path('routes/account/staff.php')
       ]);
```

- firstOr() function to BelongsToMany relation

https://github.com/laravel/framework/pull/40828
```php
$post = $user->posts()->firstOr(function () {
    // return default post...
});
```

- filtering of route:list by domain

https://github.com/laravel/framework/pull/40970
```php
php artisan route:list --domain=example.com
```

- doesntContain to higher order proxies

https://github.com/laravel/framework/pull/41034
```php
User::latest()->take(5)->get()->doesntContain('type','admin'); //true
```

- Attribute Make Method 

static constructor method to the Eloquent Attribute class, which provides convenience as follows
https://github.com/laravel/framework/pull/41014
```php
// 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();
```

- Array keyBy Method

`` Arr::keyBy() `` method which works like the collection `` keyBy() `` method
https://github.com/laravel/framework/pull/41029
```php
$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
]
*/
```

- 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
```php
$this->artisan('Hello World')->expectsOutputToContain('Hello');
```

- 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
```php
Str::betweenFirst('[a]ab[b]', '[', ']'); // a
Str::betweenFirst('foofoobar', 'foo', 'bar'); // foo
Str::betweenFirst('hannah', 'ha', 'ah'); // nn
Str::betweenFirst('dddabcddd', 'a', 'c')); // b
```

- 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

```php
$request->validate(
    [
        'foo' => [new Example]
    ],
    [
        Example::class => 'My custom message goes here!'
    ]
);
```

- 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