Herkese merhaba, Veri tabanımdan eklenen son ürünün daha önce ki üründen önce gelmesini sağlamak istiyorum.
resim de gördüğünüz gibi yeni eklenen ürün listenin sonuna ekleniyor ama ben bu sıralamayı değiştirmek istiyorum.
Nasıl bir düzenleme yapmam gerekiyor acaba ?
$product = Product::with(['prices' => function ($q) {
return $q->whereNull('user_id');
}])
->with(
'property',
'prices.prices',
'prices.edu',
'prices.eduusers',
'prices.prices.product',
'offer',
'offer.offerPrice'
)
->where('status', 1);
if ($request->has('type')) {
$product = $product->where($request->type, $id)->first();
} else {
$product = $product->findOrFail($id);
}
$productType = $product->product_type;
$prices = [];
foreach ($product->prices as $key => $price) {
if ($price->visibility) {
$prices[] = $price;
}
}
$prices = Arr::sort($prices, function ($value) {
if (Arr::exists($value, 'education')) {
return Carbon::parse($value['edu']['date'])->timestamp;
}
});
$prices = array_values($prices);
$product = $product->toArray();
dd($product);
$product['prices'] = $prices;
$data['product'] = $product;
$data['discount'] = Discount::where('status', true)
->productType($productType)
->first();
$data['my_discounts'] = DB::table('user_discount')
->where('user_id', auth()->user()->id)
->pluck('product_id');
return response()->json($data);