Laravel - Orderby Random using rand() and DB::raw() example (ok)
https://www.itsolutionstuff.com/post/laravel-5-orderby-random-using-rand-and-dbraw-exampleexample.html
Laravel - Orderby Random using rand() and DB::raw() example (ok)
By Hardik Savani May 4, 2016 Category : LaravelPlayUnmuteLoaded: 1.17%FullscreenSometimes, we require to get randomly data using laravel query builder. you can use mysql rand() with order by. If you want to get random data using laravel eloquent then we need to use DB::raw(). In bellow example you can i use DB::raw().
In this example i use DB::raw('RAND()') inside orderBy() and also add limit of 8 number of record, so you can easily implement in your laravel project. so let's try...
Read Also: Order by using multiple columns and manually array field in Laravel?
PreviousOrder by using multiple columns and manually array field in Laravel? DB::rawNextHow to use groupby having with DB::raw in Laravel Query Builder? (ok)
Last updated
Was this helpful?