fzaninotto/Faker

How to generate a column data depend on other column data

abhimanusharma opened this issue · 1 comments

Summary

I am trying to insert a record, for example, Total runs and highest scores. In this case, total runs can not be less than highest scores.

Versions

Version
PHP 7.3.0
fzaninotto/faker ^1.9
use Faker\Generator as Faker;

$factory->define(App\Player::class, function (Faker $faker) {
return [
        'total_runs' => $faker->randomNumber(4),
        'highest_scores' => $faker->randomNumber(3),
     ];
});

Is there a direct method other than this?

$total_runs = $faker->randomNumber(4);
$highest_scores = $faker->randomNumber(3);
if($highest_scores > $total_runs){ $highest_scores = $total_runs - 1;}
return[
         'total_runs' => $total_runs,
         'highest_scores' => $highest_scores,
];

I've tried searching on google and looked in previous issues but could not found anything related to this. Please help.

Maybe it works for you.

$total_runs = $faker->randomNumber(4);
$highest_scores = $faker->numberBetween(0, min($total_runs, 999));