New Things Added - Laravel 9.17 and 9.18 Released
Tags: laravel, webdev, php, programming
Published: 2022-06-22 17:50:28

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

- Define nested "with" relations via a nested array
https://github.com/laravel/framework/pull/42690

way to define nested eager loading relationships via a nested array
```php
// Using dot notation
$books = Book::with('author.contacts')->get();
 
// Nested array
$books = Book::with([
    'author' => [
        'contacts',
        'publisher',
    ],
])->get();
```

- Add host methods to the Illuminate Request object
https://github.com/laravel/framework/pull/42797

three convenience methods on the Illuminate Request instance to access underlying Symphony methods
```php
$request->host(); // getHost()
$request->httpHost(); // getHttpHost()
$request->schemeAndHttpHost(); // getSchemeAndHttpHost()
```

- Introduce fake() helper
https://github.com/laravel/framework/pull/42844


fake() helper function that allows you to easily access a singleton faker instance. Using this helper is helpful when prototyping, testing, and generating factory and seed data
```php
@for($i = 0; $i < 10; $i++)
    <dl>
        <dt>Name</dt>
        <dd>{{ fake()->name() }}</dd>
 
        <dt>Phone</dt>
        <dd>{{ fake()->phoneNumber() }}</dd>
 
    </dl>
@endfor
```
Here's an example of locale-specific faker usage
```php
fake()->name() // config('app.faker_locale') ?? 'en_US'
fake('en_AU')->name() // en_AU
```

- Allow handling cumulative query duration limit per DB connection
https://github.com/laravel/framework/pull/42744


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cin42200h3vimdy6sliq.png)

- Invokable Custom Validation Rules
https://github.com/laravel/framework/pull/42689

// without Invokable
```php
php artisan make:rule BirthYearRule
```
let's add custom rules to our BirthYearRule
```php
<?php

namespace App\Rules;

use Illuminate\Contracts\Validation\Rule;

class BirthYearRule implements Rule
{
    /**
     * Create a new rule instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Determine if the validation rule passes.
     *
     * @param  string  $attribute
     * @param  mixed  $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
        return $value >= 1990 && $value <= date('Y');
    }

    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        return 'The :attribute must be between 1990 to '.date('Y').'.';
    }
}

// use 
use App\Rules\BirthYearRule;

 public function rules()
    {
        return [
            'name' => 'required',
            'birth_year' => [
                'required',
                new BirthYearRule()
            ]
        ];
    }
```
// Now with Invokable

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4z9dn74wxj3yteephin9.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z6q899s0tf1hu3hq3t34.png)


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-9-18-0
Source :- https://www.youtube.com/watch?v=DEMlr9HiuSU