首頁  >  文章  >  php框架  >  Laravel 7.6 發布囉! ! !

Laravel 7.6 發布囉! ! !

藏色散人
藏色散人轉載
2020-04-21 13:11:513344瀏覽

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

集合新增“until” 方法

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

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

此方法採用閉包或值與集合進行比較。

String Empty Methods

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

$string = new \Illuminate\Support\HtmlString(&#39;&#39;); 
// Previously
if (empty($string->toHtml()))
// Using isEmpty
if ($string->isEmpty())

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

use Illuminate\Support\Stringable;
(new Stringable())->isNotEmpty(); // false
(new Stringable(&#39;Hello World&#39;))->isNotEmpty(); // true

Stringable 類別的Trim 方法

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

use Illuminate\Support\Stringable;
echo (new Stringable(&#39; Hello World&#39;))->ltrim(); // &#39;Hello World&#39;
echo (new Stringable(&#39;Hello World &#39;))->rtrim(); // &#39;Hello World&#39;
echo (new Stringable(&#39;/example/&#39;))->rtrim(&#39;/&#39;); // &#39;/example&#39;

特定路由忽略中間件

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

Route::get(&#39;/something&#39;)
    ->skipMiddleware(VerifyCsrfToken::class)
Route::get(&#39;/teams/create&#39;)
    ->skipMiddleware(VerifyUserHasTeam::class)

Http 用戶端:取得JSON 回應作為物件

Adrian Nürnberger 貢獻了object() 方法,可以傳回物件形式的JSON 回應體而不是一個關聯陣列:

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

元件別名

Dries Vints 貢獻了為元件設定別名:

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

Blade::component(Svg::class, &#39;heroicon-o-bell&#39;);

這比d83b4d8a88cde115fa706f73a95a53ef 這種方式比較簡潔。將別名加入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 的完整發行說明可在最新的v7 changelog 中找到:

v7.6.0

新增

● 新增Collection::until() 方法(##32262)

● 新增HtmlString::isEmpty () 方法(#32289, #32300)

● 新增Illuminate\Support\Stringable::isNotEmpty()方法(#32293)

● Illuminate\Support\Stringable 類別新增ltrim()rtrim() 方法(#32288)

● 新增忽略中間件的功能(#32347, 412261c)

# ● 新增Illuminate\Http\Client\Response::object() 方法(#32341)

● 支援設定元件別名(#32346)

● 新增Illuminate\Database\Eloquent\Collection::append() 方法(#32324)

● BelongsToMany 的pivot 欄位新增「between」語句(#32364)

● 佇列監聽支援retryAfter() 方法(#32370012370 )

● 新增對composer 新版installed.json 的格式支援(#32310)

● 資料庫遷移檔案新增uuid 變更支援(#32316)

● 允許保存資源到postgresql bytea (#32319)

修復

●修正phpredis 的*scan 方法(#32336)

● 修復Illuminate\Auth\Notifications\ResetPassword::toMail() (#● 32345)

● 在Illuminate\Translation\Translator::__construct() 呼叫setLocale  (1c6a504)

#●使用對應來防止不必要的陣列存取in Illuminate\Http\Resources\Json\PaginatedResourceResponse::toResponse() (#32296)

● 當pivot 未被修改的時候阻止時間戳更新(#32311)

● 修復CURRENT_TIMESTAMP 在Illuminate\Database\Schema\Grammars\MySqlGrammar  中的精確度bug (#32298)

修改

● HtmlString 的建構子增加預設值(#32290)

● 使用BindingResolutionException 標示容器解析問題(#32349)

● Illuminate\Validation\Concerns\ValidatesAttributes.php :: validateUrl() 使用Symfony/Validator 5.0.7 匹配(#32315)

棄用

# ● 棄用elixir 函數(#32366)

本文系轉載:

原文網址:https://learnku.com /laravel/t/43480

以上是Laravel 7.6 發布囉! ! !的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:learnku.com。如有侵權,請聯絡admin@php.cn刪除