Laravel select random row from table

Updated: 22th December 2019
Tags: php laravel sql

Get randow row from table in laravel 5.3+

$randomRow = DB::table('table')
            ->inRandomOrder()
            ->first();

Get randow id from table in laravel 5.3+

$randomId = DB::table('table')
            ->inRandomOrder()
            ->value('id');