jeudi 27 septembre 2018

Column value as index to generate 2 level collection

I am trying to get a collection which has index as column values. First level will have product_id as index and second level will have stock_date.

$data = Model::select('column1', 'product_id', 'stock_date')
                         ->where('some condition')
                         ->get();

$data = collect($data)->groupBy('product_id');

With the code above, I get the collection with product_id as the indexes.

I need the data of each product indexed by stock_date

If, for example, for product_id - 1, I have multiple records, I tried

$product_details = collect($data[1])->groupBy('stock_date');

But it does not index the records with stock_date further.

Need help to index them with stock_date.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2y4MGSf
via IFTTT

Aucun commentaire:

Enregistrer un commentaire