Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

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

Open
abhimanusharma opened this issue Jun 26, 2020 · 1 comment
Open

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

abhimanusharma opened this issue Jun 26, 2020 · 1 comment

Comments

@abhimanusharma
Copy link

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
Copy link
Contributor

raphaeldealmeida commented Sep 24, 2020

Maybe it works for you.

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants