In L-4 it was simple:
$random_quote = Quotation::all()->random(1);
But now in L-5 not a single method described in this post is working: Lar
These works but probably you didn't use the right namespace
, just use the use
statement at the top of your class
name like this:
Then you may use in your method
something like this:
// You may add: use DB; at the top to use DB instead of \DB
$random_quote = Quotation::orderBy(\DB::raw('RAND()'))->first();
Or this:
$random_quote = Quotation::orderByRaw("RAND()")->first();
Update (Since Laravel - 5.2):
$random_quote = Quotation::inRandomOrder()->first();