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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

刪除 Laravel 集合的關(guān)鍵“數(shù)據(jù)”

刪除 Laravel 集合的關(guān)鍵“數(shù)據(jù)”

PHP
冉冉說 2023-09-22 17:05:46
我需要從 Laravel 的集合中刪除“data”鍵。這對我有用,但它刪除了我想要保留的其他鍵,我只需要刪除“數(shù)據(jù)”鍵:return $filteredValues = $collection->values ()->all(); // I remove other keys inside the objects.我的收藏返回:$records = Item::where('tienda_id',$id)->where('item.nombre', 'like', "%" . $query . "%")->take(50)->get();return $collection = new ItemCollection($records);我的物品收藏.php<?phpnamespace App\Http\Resources;use Illuminate\Http\Resources\Json\ResourceCollection;use Illuminate\Support\Facades\Storage;class ItemCollection extends ResourceCollection{    /**     * Transform the resource collection into an array.     *     * @param  \Illuminate\Http\Request  $request     * @return mixed     */    public function toArray($request)    {        return $this->collection->transform(function($row, $key) {            return [                'id' => $row->id,                'nombre' => $row->nombre,                'marca_id' => $row->marca_id,                'tienda_id' => $row->tienda_id,                'nombre_marca' => $row->marca->nombre_marca,                'unidad_id' => $row->unidad_id,                'nombre_unidad' => $row->unidad->nombre_unidad,                'tipo_cambio' => $row->tienda->tipocambio,                'categoria_id' => $row->categoria_id,                'stock' => $row->stock,                'moneda' => $row->moneda,                'codigos' => $row->codigos,                'stockminimo' => $row->stockminimo,                'stockmaximo' => $row->stockmaximo,                'impuesto_id' => $row->impuesto_id,                'primer_margen' => $row->primer_margen,                'segundo_margen' => $row->segundo_margen,                'precio' => $row->precio,                'notas' => $row->notas,                'imagen' => url('images/'.$row->imagen),            ];        });    }}
查看完整描述

1 回答

?
繁華開滿天機

TA貢獻1816條經(jīng)驗 獲得超4個贊

AppProvider.php或類似中添加以下內(nèi)容。這將禁用 ItemCollections 的數(shù)據(jù)包裝。我希望您重新考慮一下,如果您需要在響應中使用分頁或元屬性,那么如果沒有數(shù)據(jù)包裝,您就沒有地方可以放置它們,這就是使用它的原因之一。

public function boot(){
    ItemCollection::withoutWrapping();
}


查看完整回答
反對 回復 2023-09-22
  • 1 回答
  • 0 關(guān)注
  • 157 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

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