第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

從 Laravel db 創(chuàng)建關(guān)聯(lián)數(shù)組

從 Laravel db 創(chuàng)建關(guān)聯(lián)數(shù)組

PHP
揚(yáng)帆大魚 2023-10-01 17:22:16
目前我正在構(gòu)建一個(gè)帶有 flutter 的應(yīng)用程序,但我的 Laravel api 控制器沒有返回適當(dāng)?shù)亩嗑S數(shù)組。我想要 { [0]=> 數(shù)組,[1]=> 數(shù)組等}。如果有人知道解決此問題的方法,我們將不勝感激public function index()    {        $payments = Payment::all();        return $payments;    }它返回這個(gè):[    {        "id": 1,        "description": "test",        "price": "9.00",        "currency": "EUR",        "status": "open",        "deleted_at": null,        "created_at": "2020-08-10T09:50:52.000000Z",        "updated_at": "2020-08-10T09:50:52.000000Z"    },    {        "id": 2,        "description": "test",        "price": "3.00",        "currency": "USD",        "status": "open",        "deleted_at": null,        "created_at": "2020-08-13T19:06:23.000000Z",        "updated_at": "2020-08-13T19:06:23.000000Z"    }]我嘗試了很多,這讓我最接近,但后來我得到了 1:{ARRAY}我嘗試過的代碼:public function index()    {        $data = [];        $payments = Payment::all();        $id=1;        foreach($payments as $payment){            array_push($data,[$id=>$payment]);            $id++;        }        return $data;    }結(jié)果:[    {        "1": {            "id": 1,            "description": "test",            "price": "9.00",            "currency": "EUR",            "status": "open",            "deleted_at": null,            "created_at": "2020-08-10T09:50:52.000000Z",            "updated_at": "2020-08-10T09:50:52.000000Z"        }    },    {        "2": {            "id": 2,            "description": "test",            "price": "3.00",            "currency": "USD",            "status": "open",            "deleted_at": null,            "created_at": "2020-08-13T19:06:23.000000Z",            "updated_at": "2020-08-13T19:06:23.000000Z"        }    }    ]我想擁有:{1:{   "message":"test",   "price":"9"   "currency":"EUR"  },2:{   "message":"test",   "price":"9"   "currency":"EUR"}
查看完整描述

2 回答

?
慕勒3428872

TA貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超6個(gè)贊

也試試這個(gè)


  public function index(){

    $payments = Payment::all();

    return response()->json([$payments]);

 }


查看完整回答
反對(duì) 回復(fù) 2023-10-01
?
BIG陽(yáng)

TA貢獻(xiàn)1859條經(jīng)驗(yàn) 獲得超6個(gè)贊

也試試這個(gè)


  public function index(){

    $payments = Payment::all();

    return response()->json([$payments]);

 }


查看完整回答
反對(duì) 回復(fù) 2023-10-01
  • 2 回答
  • 0 關(guān)注
  • 137 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)