亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

刪除 Laravel 集合的關鍵“數據”

刪除 Laravel 集合的關鍵“數據”

PHP
冉冉說 2023-09-22 17:05:46
我需要從 Laravel 的集合中刪除“data”鍵。這對我有用,但它刪除了我想要保留的其他鍵,我只需要刪除“數據”鍵: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條經驗 獲得超4個贊

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

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


查看完整回答
反對 回復 2023-09-22
  • 1 回答
  • 0 關注
  • 155 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號