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
// 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
$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
@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
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
- Invokable Custom Validation Rules https://github.com/laravel/framework/pull/42689
// without Invokable
php artisan make:rule BirthYearRule
let's add custom rules to our BirthYearRule
<?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
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
Top comments (0)