Laravel 7.6 發布啦!!!

laravel 團隊昨天發布了 v7.6.0,其中包含 13 個新功能以及 7.x 分支的最新修復和更改:

集合新增 “until” 方法

Jason McCreary 貢獻了 Collection::until() 方法, 該方法可以循環遍歷集合直到元素滿足條件再將該元素返回:

//?Before [$before,?$after]?=?$primes->partition(function?($item)?{ ????return?$item?dump(); //?Using?until $passed?=?$primes->until(11)->dump();

此方法采用閉包或值與集合進行對比。

String Empty Methods

Mark van den Broek 為 Stringable 和 HtmlString 提供了一些便利方法。第一個,HtmlString::isEmpty() 方法讓我們檢測空實例更加方便:

$string?=?new?IlluminateSupportHtmlString('');? //?Previously if?(empty($string->toHtml())) //?Using?isEmpty if?($string->isEmpty())

其次,Mark 也貢獻了 isNotEmpty() 方法

use?IlluminateSupportStringable; (new?Stringable())->isNotEmpty();?//?false (new?Stringable('Hello?World'))->isNotEmpty();?//?true

Stringable 類的 Trim 方法

Ryan Chandler 為 Stringable 類貢獻了 ltrim 和 rtrim 方法,可以修剪字符串開頭和結尾的字符:

use?IlluminateSupportStringable; echo?(new?Stringable('?Hello?World'))->ltrim();?//?'Hello?World' echo?(new?Stringable('Hello?World?'))->rtrim();?//?'Hello?World' echo?(new?Stringable('/example/'))->rtrim('/');?//?'/example'

特定路由忽略中間件

@dsazup 提供了在定義路由時跳過中間件的功能:

Route::get('/something') ????->skipMiddleware(VerifyCsrfToken::class) Route::get('/teams/create') ????->skipMiddleware(VerifyUserHasTeam::class)

http 客戶端:獲取 json 響應作為對象

Adrian Nürnberger 貢獻了 Object() 方法,可以返回對象形式的 JSON 響應體而不是一個關聯數組

//?Array?access Http::get('some-api.wip')['result']; //?Using?json() $response?=?Http::get('some-api.wip')->json(); $response['result'] //?New?option $response?=?Http::get('some-api.wip')->object(); $response->result;

組件別名

Dries Vints 貢獻了 為組件設置別名:

我遇到一個場景,其中我需要根據組件的別名有條件地呈現組件的內容。 例如,當您有一個 Svg 組件并使用 作為該組件的別名時,如下所示:

Blade::component(Svg::class,?'heroicon-o-bell');

這比 這種方式更加簡潔。 將別名添加到 Component 類將為 Blade 組件增加許多新的用法和可能性…

append Attributes Across an Eloquent Collection

Niels Faurskov 貢獻了一個 eloquent 集合方法 append() ,他可以向集合中附加特定屬性:

//?Before?Laravel?7.6 $collection->each(function($model)?{ ????$model->append($attribute) }); //?Append?method $collection->append($attribute);

支持 Retry-After 方法

@RyanDaDeng 貢獻了個方法級的支持,他可以對隊列監聽器的? retryAfter 進行補充,以適用更高級的用例:

//?listener?implementation public?function?retryAfter() { ????//?自定義?retryAfter?邏輯 }

支持 composer 新版 installed.json 格式

Jakub Arbet 支持 Composer 2 新版本的快照功能 (尚未穩定), 但仍與舊版本的 composer 向后兼容:

在 composer 的最新快照版本中更改了 vendor/composer/installed.json 的格式,從而破壞了自動發現軟件包的功能。 此 PR 通過較早版本的 composer 向后兼容來解決此問題。

UUID 支持更改

Mathieu Tudisco 支持在 uuid 列使用 change()? 方法,在此之前會導致以下錯誤:

Unknown?column?type?“uuid”?requested.

發行說明

您可以在下面查看 github 上的新功能和更新的完整列表以及 7.5.0 and 7.6.0](https://github.com/laravel/framework/compare/v7.5.0…v7.6.0) 之間的區別。 Laravel 7.x 的完整發行說明可在最新的 https://github.com/laravel/framework/compare/v7.5.0…v7.6.0 中找到:

v7.6.0

新增

● 新增 Collection::until() 方法 (https://github.com/laravel/framework/compare/v7.5.0…v7.6.0)

●?新增 HtmlString::isEmpty() 方法 (https://github.com/laravel/framework/compare/v7.5.0…v7.6.0, https://github.com/laravel/framework/compare/v7.5.0…v7.6.0)

●?新增 IlluminateSupportStringable::isNotEmpty() 方法 (https://github.com/laravel/framework/compare/v7.5.0…v7.6.0)

●?IlluminateSupportStringable 類新增 ltrim() 和 rtrim() 方法 (https://github.com/laravel/framework/compare/v7.5.0…v7.6.0)

●?新增忽略中間件的功能 (https://github.com/laravel/framework/compare/v7.5.0…v7.6.0, https://github.com/laravel/framework/compare/v7.5.0…v7.6.0)

●?新增 IlluminateHttpClientResponse::object() 方法 (https://github.com/laravel/framework/compare/v7.5.0…v7.6.0)

●?支持設置組件別名 (https://github.com/laravel/framework/compare/v7.5.0…v7.6.0)

●?新增 IlluminatedatabaseEloquentCollection::append() 方法 (#https://github.com/laravel/framework/compare/v7.5.0…v7.6.0)

●?BelongsToMany 的 pivot 列新增 “between” 語句 (https://github.com/laravel/framework/compare/v7.5.0…v7.6.0)

●?隊列監聽支持 retryAfter() 方法 (https://github.com/laravel/framework/compare/v7.5.0…v7.6.0)

●?新增對 composer 新版 installed.json 的格式支持 (https://github.com/laravel/framework/compare/v7.5.0…v7.6.0)

●?數據庫遷移文件新增 uuid 更改支持 (https://github.com/laravel/framework/compare/v7.5.0…v7.6.0)

●?允許保存資源到 postgresql bytea (https://github.com/laravel/framework/compare/v7.5.0…v7.6.0)

修復

●?修復 phpredis 的 *scan 方法 (https://github.com/laravel/framework/compare/v7.5.0…v7.6.0)

●?修復 IlluminateAuthNotificationsResetPassword::toMail() (https://github.com/laravel/framework/compare/v7.5.0…v7.6.0)

●?在 IlluminateTranslationTranslator::__construct() 調用 setLocale? (https://github.com/laravel/framework/compare/v7.5.0…v7.6.0)

●?使用映射來防止不必要的數組訪問 in IlluminateHttpResourcesJsonPaginatedResourceResponse::toResponse() (https://github.com/laravel/framework/compare/v7.5.0…v7.6.0)

●?當 pivot 未被修改的時候阻止時間戳更新 (https://github.com/laravel/framework/compare/v7.5.0…v7.6.0)

●?修復 CURRENT_TIMESTAMP 在 IlluminateDatabaseSchemaGrammarsMySqlGrammar? 中的精度 bug (https://github.com/laravel/framework/compare/v7.5.0…v7.6.0)

修改

●?HtmlString 的構造函數增加默認值 (https://github.com/laravel/framework/compare/v7.5.0…v7.6.0)

●?使用 BindingResolutionException 標示容器解析問題 (https://github.com/laravel/framework/compare/v7.5.0…v7.6.0)

●?IlluminateValidationConcernsValidatesAttributes.php ::validateUrl() 使用 symfony/Validator 5.0.7 匹配 (https://github.com/laravel/framework/compare/v7.5.0…v7.6.0)

棄用

●?棄用 elixir 函數 (https://github.com/laravel/framework/compare/v7.5.0…v7.6.0)

本文系轉載:原文地址:https://learnku.com/laravel/t/43480

? 版權聲明
THE END
喜歡就支持一下吧
點贊5 分享