Currently, in my ModelFactory.php, I have:
$factory->define(App\\Reply::class, function (Faker\\Generator $faker) {
return [
\'thread_id\' => 1,
It may not be that efficient but you can use it:
User::all('id')->random();
or
rand(1,User::count());
or
User::inRandomOrder()->limit(1)->get();
First one will be more faster than User::all()->random()->id; because that all function by default gets '*' as column name parameter. So, it will get all the columns for all the rows.