如何获得随机行laravel-5 [英] how get random row laravel-5
本文介绍了如何获得随机行laravel-5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在L-4中,这很简单:
In L-4 it was simple:
$random_quote = Quotation::all()->random(1);
但是现在在L-5中,这篇文章中描述的一种方法并不工作:
Laravel - 雄辩或流畅的随机行
But now in L-5 not a single method described in this post is working: Laravel - Eloquent or Fluent random row
我的视图文件只是空白。任何想法?
My view file just gets blank. Any ideas?
编辑:
已解决:
$ random_quote = Quotation :: orderByRaw(RAND()) - > first();
Solved: $random_quote = Quotation::orderByRaw("RAND()")->first();
推荐答案
Laravel 5.4的更新
Update for Laravel 5.4
新的randomsorting在Laravel 5.4
- > inRandomOrder() - > first()
这篇关于如何获得随机行laravel-5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文