We are using Faker for our Laravel app. For a table we have 2 columns, start date
and end date
. How to call faker in a way that the end date
will always be greater than start date
Create a random start date in the space of time you wish:
$start = $faker->dateTimeBetween('next Monday', 'next Monday +7 days');
Then use the returned start date as the minimum input for the end date and make sure that the upper boundary for your end date is also after your start date.
$end = $faker->dateTimeBetween($start, $start->format('Y-m-d H:i:s').' +2 days');
You may also consider using Alice for creating fixtures using nice and readable YAML. You can use variables in Alice code to achieve your goal.
For the relative date/time syntax checkout the PHP docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With