Skip to content

Commit fd7bd7b

Browse files
committed
Update ProductListController to filter out trashed products and use inRandomOrder for product retrieval
This commit modifies the index, adsProducts, and allProducts methods in the ProductListController to ensure that only non-trashed products are returned. Additionally, it changes the product retrieval order to inRandomOrder, enhancing the randomness of the product listings.
1 parent f88df18 commit fd7bd7b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

app/Http/Controllers/Product/ProductListController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
class ProductListController extends Controller
1111
{
1212
public function index(){
13-
return ProductResource::collection(Product::orderBy('created_at', 'desc')->where('status',1)->inRandomOrder()->take(5)->get());
14-
}
13+
return ProductResource::collection(Product::inRandomOrder()->where('status',1)->where('is_trashed',0)->take(5)->get());
14+
}
1515

1616
public function adsProducts($id){
17-
return ProductResource::collection(Product::Where('subscribe_id',$id)->where('status',1)->inRandomOrder()->get());
17+
return ProductResource::collection(Product::inRandomOrder()->Where('subscribe_id',$id)->where('status',1)->where('is_trashed',0)->get());
1818
}
1919
public function allProducts(){
20-
return ProductResource::collection(Product::orderBy('created_at', 'desc')->where('status',1)->paginate(6));
20+
return ProductResource::collection(Product::inRandomOrder()->where('status',1)->where('is_trashed',0)->paginate(6));
2121
}
2222
}

0 commit comments

Comments
 (0)