Laravel 9.35 發布啦!看看都有哪些新變化?

下面由laravel教程欄目給大家介紹關于最新發布的laravel 9.35版本都有哪些變化,希望對大家有所幫助!

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

Laravel 團隊發布了9.35版本,它有一個新的令人興奮的備用郵件語法、一個Eloquent的 “嚴格模式” 功能等。

備用郵件語法

Taylor Otwell?通過返回 “指定可郵件內容和屬性的精簡對象”,貢獻了一個可郵件語法。

這是他的一個例子?pull request description:

namespace AppMail;  use IlluminateBusQueueable; use IlluminateContractsQueueShouldQueue; use IlluminateMailMailable; use IlluminateMailMailablesAddress; use IlluminateMailMailablesAttachment; use IlluminateMailMailablesContent; use IlluminateMailMailablesEnvelope; use IlluminateQueueSerializesModels;  class InvoicePaid extends Mailable {     use Queueable, SerializesModels;      /**      * 創建一個郵件實例      *      * @return void      */     public function __construct()     {         //     }      /**      * 獲取郵件信封      *      * @return IlluminateMailMailablesEnvelope      */     public function envelope()     {         return new Envelope(             subject: 'Invoice Paid',             cc: [new Address('foo@example.com', 'Example Name')],             tags: [],             metadata: [],         );     }      /**      * 獲取郵件內容定義      *      * @return IlluminateMailMailablesContent      */     public function content()     {         return new Content(             view: 'html-view-name',             text: 'text-view-name',         );     }      /**      * 獲取郵件的附件      *      * @return IlluminateMailMailablesAttachment[]      */     public function attachments()     {         return [             Attachment::fromPath('/path/to/file'),         ];     } }

使用build() 定義郵件的傳統方式不會被刪除。 我喜歡上面的例子是因為使用 php 8 的命名參數更一目了然。

Eloquent “嚴格”模式

Chris Morrell 和 Taylor Otwell 合作開發了 Eloquent 嚴格模式,該模式支持以下功能:

  • 沒有延遲加載
  • 分配不可填充屬性時的例外情況
  • 訪問未檢索或不存在的屬性的異常

要在開發中使用嚴格模式,方法是將以下內容添加到已注冊服務提供者的 boot() 方法中:

Model::shouldBeStrict();

shouldBeStrict() 方法是啟用以下所有功能的快捷方式:

Model::preventLazyLoading(); Model::preventSilentlyDiscardingAttributes(); Model::preventsAccessingMissingAttributes();

使用資源路由加載廢棄模型

Andrew Brown?提供了使用以下路由語法加載帶有資源路由的廢棄模型的能力:

// 所有終結點 Route::resource('users', UserController::class)->withTrashed();  // 僅`顯示` Route::resource('users', UserController::class)->withTrashed(['show']);

發行說明

你可以在github上看到下面完整的新功能和更新列表以及[9.34.0]和9.35.0](github.com/laravel/framework/compa…)?之間的區別。以下發行說明直接來自?changelog:

v9.35.0

添加

  • 允許為資源路由加載廢棄模型 (#44405)
  • 添加到?Illuminate/database/Eloquent/Model::shouldBeStrict()?和其他 (#44283)
  • 沒有解析控制器的控制器中間件 (#44516)
  • 選擇可郵寄的語法 (#44462)

修復

  • 修復自引用多對多關系中的聚合函數(withSum 等)問題(#44286)
  • 修復了使用靜態類屬性作為模板屬性的問題 (#44473)
  • Traversable 在 Enumerate Values 中應該優先于 JsonSerializable(#44456)
  • 修復了make:cast –inbound,所以它是一個布爾選項,而不是值 (#44505)

修改

  • 測試方法。 使用 json_encode 使錯誤消息更具可讀性(#44397)
  • 讓 Model::without Timestamps() 返回回調的返回值 (#44457)
  • 僅在相關路由上加載廢棄模型(#44478)
  • 向 shouldBlockPhpUpload 函數添加額外的 PHP 擴展 (#44512)
  • 為特別嘈雜的對象注冊 cutInternals casters (#44514)
  • 使用 get 方法訪問應用程序區域設置 (#44521)
  • 僅返回來自頻道的非空響應 (09d53ee,?3944a3e)
  • 正確的頻道匹配 (#44531)
  • 遷移郵件組件 (#44527)

原文地址:https://laravel-news.com/laravel-9-35-0

譯文地址:https://learnku.com/laravel/t/72658

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