29
AprThe team Laravel has released the latest version of Laravel v9.10.0. This new release incorporates many updates, new features, and bug fixes. Laravel 9.10 version includes a findOr()
Eloquent method, a new command assertion, retrieving input as a Stringable instance, and much more. Here are some of the new features and updates:
Jess Archer introduced a findOr()
method to the Eloquent Builder and Relations. This matches the existing firstOr()
methods.
A typical scenario where this method is useful is when a resource route (e.g. /posts/1) cannot find a model that is not part of the URL, and so a findOrFail()
returning a 404 is not appropriate.
Example usage:
User::findOr(1, fn () => throw new RuntimeException);
User::findOr(1, fn () => abort(403));
User::findOr(1, fn () => 'return something');
The method also supports passing columns as the second argument:
User::findOr(1, ['columns'], fn () => '...');
It also works on HasMany
, HasManyThrough
, BelongsToMany
, MorphMany
, and MorphToMany
relations:
$user->posts()->findOr(1, fn () => '...');
doesntExpectOutputToContain
assertion methodMarkus Hebenstreit contributed to this PR that adds the new Command assertion method doesntExpectOutputToContain
in Laravel
Artisan::command('contains', function () {
$this->line('My name is Taylor Otwell');
});
$this->artisan('contains')
->doesntExpectOutputToContain('Taylor Otwell')
Rok Sprogar pull request adds beforeRefreshingDatabase
to Testing/RefreshDatabase
trait. This function is very useful for the Laravel developers because it allows for running just about anything before the database is refreshed.
class DataExportTest extends TestCase
{
use RefreshDatabase;
protected $seed = true;
protected function beforeRefreshingDatabase()
{
$this->artisan('db:wipe --database another-database-connection');
}
public function test_prepare_some_data()
{
...
}
}
It is not possible to use the IS
or IS NOT
operators for example in the whereRelation()
function. The problem is that the Illuminate\Database\Query\Builder
does not support these operators. It would work if these operators were included in this array.’ The whereRelation()
calls internally the where()
function inside the Illuminate\Database\Query\Builder
, which changes unsupported operators to =
. This is the reason why some queries raises an SQL exception.
Markus Koch contributed to this Pr that adds support for is and is not operators when using PostgreSQL.
View more details on this link.
Right now, the only way to translate password errors is to set messages into a JSON
file. And we can’t use lang/{language}/validation.php
in our system to translate error messages.
Reza Amini contributed a change, which will enable us to use PHP files to use translation. For example, we can change the lang/en/validation.php
file into:
return [
'password' => [
'mixedCase' => 'The :attribute must contain at least one uppercase and one lowercase letter.',
'letters' => 'The :attribute must contain at least one letter.',
'symbols' => 'The :attribute must contain at least one symbol.',
'numbers' => 'The :attribute must contain at least one number.',
'uncompromised' => 'The given :attribute has appeared in a data leak. Please choose a different :attribute.',
],
];
These changes do not break any old changes, and old users still can use JSON files to translate this message.
You can visit the entire list of latest features and updates and the difference between 9.9.0 and 9.10.0 on GitHub.
Published at : 29-04-2022
I am a highly results-driven professional with 12+ years of collective experience in the grounds of web application development especially in laravel, native android application development in java, and desktop application development in the dot net framework. Now managing a team of expert developers at Codebrisk.
Launch project