用法:随机显示前3个特色图片,然后是带有分页的非特色图片。我有大约17张特色图片。
我如何使用orderBy随机化。
数据库:特色:数据库中为0或1
$images = Images::OrderBy('featured', 'desc')->paginate(10);发布于 2020-12-06 00:13:42
试一试
不使用分页
//Latest 3 featured images
$top3FeaturedImages = Images::where('featured', 1)
->latest()
->take(3)
->get();
$randomUnfeaturedImages = Images::where('featured', 0)
->inRandomOrder()
->take(7)
->get();
$result = $top3FeaturedImages->concat($randomUnfeaturedImages);使用分页
$featuredImages = Images::where('featured', 1)
->latest()
->take(3)
->get();
$randomUnfeaturedImages = Images::where('featured', 0)
->inRandomOrder()
->paginate(7);
//In this case you need to pass 2 variables to the view $featuredImages & paginated $randomUnfeaturedImageshttps://stackoverflow.com/questions/65158942
复制相似问题