fzaninotto / Faker

Faker is a PHP library that generates fake data for you
MIT License
26.8k stars 3.57k forks source link

How to generate a column data depend on other column data #2020

Open abhimanusharma opened 4 years ago

abhimanusharma commented 4 years ago

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.

raphaeldealmeida commented 3 years ago

Maybe it works for you.

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