I am trying to create a Factory in Laravel that will fake an event created on a calendar. The event has a Start DateTime and End DateTime. I want the start date to be sometime in the future from now and the end dateTime to be within a few hours of the start dateTime. I keep getting the same dateTime on both start and end.
I have tried a few different methods that I found from Google and they all result in both the start and end dateTimes being identical.
use Faker\Generator as Faker;
$factory->define(App\Event::class, function (Faker $faker) {
$start_date = $faker->dateTimeBetween('+0 days', '+1 month');
$end_date = $faker->dateTimeBetween($start_date, $start_date->modify('+5 hours'));
$user = factory(App\User::class)->create();
return [
'name' => $faker->sentence,
'description' => $faker->paragraph,
'start_date_time' => $start_date,
'end_date_time' => $end_date,
'owner_id' => $user->id,
];
});
I expect the start DateTime to be between now and 1 month and, I expect the end DateTime to be between the start dateTime and 5 hours later.