Open mikeritter opened 9 years ago
I ran into this too. The problem lies in the fact that the way you're declaring the variable TestDummy uses to generate is not the data itself, but rather a quick means to tell TestDummy how it should generate the data.
In order to manipulate each date directly, you need to use a closure. From the docs (example modified):
Alternatively, you may pass a closure as the second argument to the $factory method. This can be useful for situations where you need a bit more control over the values that you assign to each attribute. Here's an example:
$factory('App\MyModel', function($faker, $overrides) {
$date = $faker->dateTimeBetween('-1 days','+1 months')->format('Y-m-d');
return [
'date' => $date
];
});
Note, the closure doesn't accept an $overrides
argument. It only accepts the $faker
instance.
Thanks for that @gbrock . This produces a date that's the same in all entries.
There seems to be a bug in defining closures introduced recently, covered in this issue. You could load the last working version in your composer.json:
"laracasts/testdummy": "2.1",
...which works for the time being (thanks @h-collector).
I had the same problem and https://github.com/laracasts/TestDummy/issues/86 helped out.
'date' => $faker->dateTimeBetween('-1 days','+1 months')->format('Y-m-d')
throws
Call to undefined method Closure::format()