Php 如何在laravel 5.6中使用chunk()和collection从数据库中获取分类产品

Php 如何在laravel 5.6中使用chunk()和collection从数据库中获取分类产品,php,laravel,laravel-5,laravel-5.6,Php,Laravel,Laravel 5,Laravel 5.6,有人能帮我解决这个问题吗?我尝试使用chunk方法根据类别获取数据,并且使用集合。但当我在集合中使用Where子句时,它会给我null值。请帮帮我 $products=DB::table('stock_management') ->join('warehouse_products','stock_management.product_id','=','warehouse_products.id') ->leftjoin('brand','warehouse_products.bran

有人能帮我解决这个问题吗?我尝试使用chunk方法根据类别获取数据,并且使用集合。但当我在集合中使用Where子句时,它会给我null值。请帮帮我

$products=DB::table('stock_management')
->join('warehouse_products','stock_management.product_id','=','warehouse_products.id')
->leftjoin('brand','warehouse_products.brand_id','=','brand.id')
->select('warehouse_products.*','brand.name as Brandname','brand.remember_token as color')
->orderBy('brand.name','ASC')
->get()
->chunk(50);

$collection=collect($products);
$getProduct=$collection->where('categories_id','=',34);
$catProduct=$getProduct->all();
dd($catProduct);
收集=收集([1,2,3,4,5,6,7])$chunks=$collection->chunk(4)$chunks->toArray();你会从这里得到灵感的