我正在返回用戶保存的所有送貨地址,但有一些值留空,并且其中的輸出為空。如何將 NULL 值轉換為空白(“”)。我在互聯網上查看了許多解決方案,但無法使其正常工作。API鏈接:https://androidapp.factory2homes.com/api/shippings/3$address = DB::table('shippings')->where('user_id' , $user_id)->get();
return $address;
1 回答

守著一只汪
TA貢獻1872條經驗 獲得超4個贊
您可以只映射返回值,如下所示:
return $address = DB::table('shippings')
->where('user_id' , $user_id)
->get()
->map(function ($item) {
$mapped = [];
foreach ($item as $key => $value) {
$mapped[$key] = $value ?? ' ';
}
return $mapped
});
- 1 回答
- 0 關注
- 209 瀏覽
添加回答
舉報
0/150
提交
取消