0
$products = DB::table('product_management')
                        ->join('seller_registration','seller_registration.id','product_management.seller_id')
                        ->join('seller_package_management','seller_package_management.id','seller_registration.package_taken_name')
                        ->where('product_management.product_name',$product_name)
                        ->where('product_management.status',1)
                        ->where('product_management.deleted_at',null)
                        ->where('seller_registration.deleted_at',null)
                        ->where('seller_registration.status',1)
                        ->where([['seller_registration.city','like','%'.$city.'%'],['seller_registration.seller_type','like','%'.$seller_type.'%']])
                        ////->where('seller_package_management.package_type','Paid')
                        ->select('seller_registration.id as sid','seller_registration.company_name','seller_registration.seller_name','seller_registration.company_logo','seller_registration.seller_type','seller_registration.phone','seller_registration.city','seller_registration.pincode','seller_registration.category_name','seller_registration.city','seller_registration.valid_up_to','product_management.id as pid','product_management.product_name','product_management.product_description','product_management.product_image','product_management.approx_price','product_management.current_price','product_management.deals_in','product_management.moq','product_management.product_specification')
                        //->groupby('seller_registration.id')
                        ->orderby('seller_registration.add_on_package','DESC')
                        ->groupby('seller_registration.id')
                        ->inrandomOrder()
                        ->get();

This is my code I want to fetch products in random order

How to get random products using my code

aynber
  • 22,380
  • 8
  • 50
  • 63
  • Which of these tables is your product? What is the issue you are getting now? What output are you expecting? – Arun A S May 25 '23 at 13:42
  • I think you have missed caps 'R' in inrandomOrder() which should be inRandomOrder(). you should check answer of @aebersold on this post with multiple examples https://stackoverflow.com/a/13931676/7725694 – Zafeer Ahmad May 25 '23 at 17:35
  • I want to fetch data from product_management table in random order... – Manoj Jangid May 26 '23 at 04:53
  • You can do the collection and the do [random](https://laravel.com/docs/10.x/collections#method-random), or just put ->inRandomOrder first. – francisco May 26 '23 at 09:23

0 Answers0