The Laravel group launched 10.4 with a Documents:: json() technique, transforming existing HasMany partnerships to a HasOne partnership, a brand-new examination feedback assertion, and also extra.
Data:: json() technique
Austin White added a Data:: json()
technique as a comfort for obtaining JSON inscribed information from a documents:
// Prior To
$ components = Data:: obtain(' sample.json');
$ information = json_decode($ components, real);
// After
$ information = Data:: json(' sample.json');
Assert in need of support media kind
Shamimul Alam added an assertion assistant for the 415 In Need Of Support Media Kind
feedback standing code:
$ feedback->> assertUnsupportedMediaType();
Transform an existing HasMany to HasOne partnership
Luke Kuzmish added transforming a HasMany to a HasOne and also a MorphMany to MorphOne
Take this instance of needing to specify 2 partnerships:
course Individual prolongs Design
{
public feature logins(): HasMany {
return $ this->> hasMany( Login:: course, ' some_id', ' the_other_id');
}
public feature latestLogin(): HasOne {
return $ this->> hasOne( Login:: course, ' some_id', ' the_other_id')->> latestOfMany();
}
}
With this public relations currently, you can do the adhering to rather with the ->> one()
technique:
course Individual prolongs Design
{
public feature logins(): HasMany {
return $ this->> hasMany( Login:: course, ' some_id', ' the_other_id');
}
public feature latestLogin(): HasOne {
return $ this->> logins()->> one()->> latestOfMany();
}
}
The one()
technique is readily available on the HasMany
, HasManyThrough
, and also MorphMany
Develop macroable technique for paginationInformation
Frans Slabbekoorn added the capability to specify a macro for paginationInformation
that permits personalizing pagination info without needing to prolong all sources as a base source:
/ ** @mixin IlluminateHttpResourcesJsonResourceCollection */
course ResourceCollectionMixin
{
public feature paginationInformation(): Closure
{
return fn ($ demand, $paginated, $default) => > accumulate($ default)->> mapWithKeysRecursively( fn ($ product, $essential) => > [Str::camel($key) => $item])->> toArray();
}
}
Launch Notes
You can see the full listing of brand-new attributes and also updates listed below and also the diff in between 10.3.0 and also 10.4.0 on GitHub. The adhering to launch notes are straight from the changelog:
v10.4.0
Included
- Included
Illuminate/Testing/Concerns/ AssertsStatusCodes:: assertUnsupportedMediaType()
( # 46426) - Included curl_error_code: 77 to DetectsLostConnections ( # 46429)
- Enable transforming a HasMany to HasOne && & & MorphMany to MorphOne ( # 46443)
- Include choice to develop macroable technique for paginationInformation ( # 46461)
- Included
Illuminate/Filesystem/Filesystem:: json()
( # 46481)
Taken Care Of
- Repair analyzed input debates for command occasions utilizing dispatcher rerouting ( # 46442)
- Repair enums utilizes with optional implied specifications ( # 46483)
- Repair deprecations for ingrained photos in symfony mailer ( # 46488)
Altered
- Included option data source port in Postgres DSN ( # 46403)
- Permit calling getControllerClass on closure-based courses ( # 46411)
- Eliminate outdated method_exists( ReflectionClass:: course, ‘isEnum’) phone call ( # 46445)
- Transform significant building contractor to base building contractor in whereExists ( # 46460)
- Refactor shared fixed methodExcludedByOptions technique to characteristic ( # 46498)