Convert laravel object to array

前端 未结 14 731
名媛妹妹
名媛妹妹 2020-12-13 19:33

Laravel output:

Array
(
    [0] = stdClass Object
    (
        [ID] = 5

    )

    [1] = stdClass Object
    (
        [ID] = 4

    )

)

相关标签:
14条回答
  • 2020-12-13 20:33

    this worked for me in laravel 5.4

    $partnerProfileIds = DB::table('partner_profile_extras')->get()->pluck('partner_profile_id');
    $partnerProfileIdsArray = $partnerProfileIds->all();
    

    output

    array:4 [▼
      0 => "8219c678-2d3e-11e8-a4a3-648099380678"
      1 => "28459dcb-2d3f-11e8-a4a3-648099380678"
      2 => "d5190f8e-2c31-11e8-8802-648099380678"
      3 => "6d2845b6-2d3e-11e8-a4a3-648099380678"
    ]
    

    https://laravel.com/docs/5.4/collections#method-all

    0 讨论(0)
  • 2020-12-13 20:37

    $foo = Bar::getBeers(); $foo = $foo->toArray();

    0 讨论(0)
提交回复
热议问题