Laravel 11.10版本發(fā)布 - 使用帶有updateOrInsert()的閉包
Laravel  /  管理員 發(fā)布于 9個月前   490
本周,Laravel團隊發(fā)布了v11.10,能夠?qū)⒒卣{(diào)傳遞給updateOrInsert,
支持帶有顯式路由模型綁定的軟刪除模型,等等。
允許向updateOrInsert()傳遞回調(diào)
Mark Eriksson將回調(diào)作為第二個參數(shù)傳遞給updateOrInsert()查詢生成器方法。
在回調(diào)中,傳遞布爾值$exists變量,這樣您就可以根據(jù)記錄是否存在來編寫更新特定列的邏輯:
DB::table('users')->updateOrInsert(
['user_id' => $user_id],
function ($exists) use ($data) {
if ($exists) {
return [
'name' => $data['name'],
'email' => $data['email'],
];
}
return [
'name' => $data['name'],
'email' => $data['email'],
'optional_column' => $data['foobar'],
];
}
);
有關(guān)完整的實施詳細信息,請參閱拉動請求#55166。
使用顯式路由模型綁定時支持軟刪除模型
Graham Bradley在使用顯式路由模型綁定時添加了對軟刪除模型的支持:
"當(dāng)使用Laravel的顯式路由模型綁定功能時,此PR允許解析軟刪除模型。
它允許開發(fā)人員在處理軟刪除模型時使用顯式路由模型綁定,而無需自定義解析邏輯。
為此,它使用與隱式綁定相同的withTrashed()方法。"
// Before
Route::get('/users/{user}', ...);
Route::bind('user', function (string $value) {
return User::where('id', $value)->withTrashed()->firstOrFail();
});
// After
Route::get('/users/{user}', ...)->withTrashed();
Route::model('user', User::class);
有關(guān)完整的實施詳細信息,請參閱“拉取請求”#51651。
允許在Mailer配置中設(shè)置重新發(fā)送API密鑰
@riasvdv直接在mailer配置中設(shè)置Resend API密鑰,而不僅僅是在服務(wù)配置中。
有關(guān)更多詳細信息,請參閱請求號51618。
發(fā)布說明
你可以在下面看到新功能和更新的完整列表,以及GitHub上11.9.0和11.10.0之間的差異。
以下發(fā)行說明直接來自更改日志:
https://github.com/laravel/framework/compare/v11.9.0...v11.10.0
https://github.com/laravel/framework/blob/e404bd90a97b2e9ed8a3d2ef53a4312658a4a49a/CHANGELOG.md#v11100---2024-06-04
v11.10.0
[11.x]通過@Henridv修復(fù)文件名中的拼寫錯誤
https://github.com/laravel/framework/pull/51643
[11.x]通過@riasvdvin將Vite自動刷新添加到錯誤頁面
https://github.com/laravel/framework/pull/51635
[11.x]在中添加@imanghafoori1對join_path的測試
https://github.com/laravel/framework/pull/51621
[11.x]在中通過@jasonmccrreary為丟失的配置文件預(yù)加載基本選項
https://github.com/laravel/framework/pull/51619
[11.x]在中添加選項以禁用@taka oyama對基本配置的合并
https://github.com/laravel/framework/pull/51579
[11.x]如果@Markshall在中已經(jīng)存在記錄,
則允許將回調(diào)傳遞給updateOrInsert()以傳遞不同的$值
https://github.com/laravel/framework/pull/51566
[11.x]通過@imanghafoori1在中修復(fù)段“0”的join_path問題
https://github.com/laravel/framework/pull/51649
[11.x]刪除中@nicolus在錯誤頁面中多余的雙引號
https://github.com/laravel/framework/pull/51670
[11.x]通過@saMahmoudzadeh在中添加測試以提高HtmlString的測試覆蓋率
https://github.com/laravel/framework/pull/51666
[11.x]添加測試以提高中@saMahmoudzadeh對Arr::whereNotNull的測試覆蓋率
https://github.com/laravel/framework/pull/51661
[11.x]在中通過@imanghafoori1為FileSystem類添加測試
https://github.com/laravel/framework/pull/51654
[11.x]在中通過@nathanpurcell更新OptimizeClearCommand.php
https://github.com/laravel/framework/pull/51667
[11.x]當(dāng)使用中@gbradley的顯式路由模型綁定時,支持軟刪除模型
https://github.com/laravel/framework/pull/51651
[11.x]添加Arr的測試::除以中的@saMahmoudzadeh
https://github.com/laravel/framework/pull/51673
[11.x]Prune應(yīng)該是@riasvdvin的標(biāo)志選項
https://github.com/laravel/framework/pull/51694
[11.x]如果app.debug在運行時被@crynobone更改為true,請避免使用Laravel新錯誤頁面
https://github.com/laravel/framework/pull/51705
轉(zhuǎn):
https://laravel-news.com/laravel-11-10-0
123 在
Clash for Windows作者刪庫跑路了,github已404中評論 按理說只要你在國內(nèi),所有的流量進出都在監(jiān)控范圍內(nèi),不管你怎么隱藏也沒用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最簡單的方法中評論 好久好久都沒看友情鏈接申請了,今天剛看,已經(jīng)添加。..博主 在
佛跳墻vpn軟件不會用?上不了網(wǎng)?佛跳墻vpn常見問題以及解決辦法中評論 @1111老鐵這個不行了,可以看看近期評論的其他文章..1111 在
佛跳墻vpn軟件不會用?上不了網(wǎng)?佛跳墻vpn常見問題以及解決辦法中評論 網(wǎng)站不能打開,博主百忙中能否發(fā)個APP下載鏈接,佛跳墻或極光..路人 在
php中使用hyperf框架調(diào)用訊飛星火大模型實現(xiàn)國內(nèi)版chatgpt功能示例中評論 教程很詳細,如果加個前端chatgpt對話頁面就完美了..
Copyright·? 2019 侯體宗版權(quán)所有·
粵ICP備20027696號