Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call to undefined method Closure::format() #81

Open
mikeritter opened this issue Mar 13, 2015 · 5 comments
Open

Call to undefined method Closure::format() #81

mikeritter opened this issue Mar 13, 2015 · 5 comments

Comments

@mikeritter
Copy link

'date' => $faker->dateTimeBetween('-1 days','+1 months')->format('Y-m-d')

throws

Call to undefined method Closure::format()

@gbrock
Copy link

gbrock commented Mar 15, 2015

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
    ];
});

@swekaj
Copy link
Contributor

swekaj commented Mar 15, 2015

Note, the closure doesn't accept an $overrides argument. It only accepts the $faker instance.

@mikeritter
Copy link
Author

Thanks for that @gbrock . This produces a date that's the same in all entries.

@gbrock
Copy link

gbrock commented Mar 18, 2015

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).

@alariva
Copy link

alariva commented Dec 9, 2015

I had the same problem and #86 helped out.

Example here

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

No branches or pull requests

4 participants