-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
Add faker() helper #41130
Add faker() helper #41130
Conversation
public function __call(string $name, array $arguments) | ||
{ | ||
return match ($name) { | ||
'image', 'alt' => $this->faker->$name(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't here be $this->$name()
instead?
Otherwise it is equal to the default
arm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rodrigopedra I think you are correcrt, code could be simplified to:
public function __call(string $name, array $arguments)
{
return $this->faker->$name();
}
Then it would still use the custom image and alt method, and pass the other calls to faker.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sure… I missed that the magic method will only be called for missing methods… might be the late hours from yesterday :)
Faker is a dev dependency, and would fail to run in production. |
@ankurk91 That's a good point. Although this helper would only make sense for development, there isn't any way to stop a developer for mistakingly use it in production. One solution might be to check the environment in the Faker magic __cal method and throw an exception when not in development mode. This might make it more clear for anyone using this helper. Although not ideal. |
@JohannesCleve An exception will be thrown in production either way, because the classes for faker won't exist in production. I think @ankurk91 concerns are that people use the faker helper in a dev environment because it works and then deploy the code to production, where it will fail. |
Feel free to add this helper to your own application! |
This pull request adds a faker() helper, primarily to use in blade views.
This makes it ease to get fake data in your Laravel blade view, without having to make a factory based on your eloquent model.
Get a collection of faker instances
Get a random image