-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[10.x] Allow Factory::count() to consume callables to be able to generate randomness during runtime. #49637
Conversation
Do you have maybe a more real-world example? In your original example couldn't you just do |
Thanks for your pull request to Laravel! Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include. If possible, please consider releasing your code as a package so that the community can still take advantage of your contributions! If you feel absolutely certain that this code corrects a bug in the framework, please "@" mention me in a follow-up comment with further explanation so that GitHub will send me a notification of your response. |
@taylorotwell Thanks for your reply! Sure, here is my current use case as a description. I am sure there are more out there. Here is a discussion with some replies which take on this topic too: #36289 I think mainly it solves randomness during development in combination with relationships. Let's say i want to make a Quiz, which has Sections and those sections have Questions.
This will create 4 Quizzes, all with the same 1-10 amount of sections and those sections with 1-10 amount of questions. By extending count to take a resolvable function we could delay the count until runtime of the factory::make call. By doing so we can create 4 Quizzes with each random count of sections and those random count of questions. So basically complete randomness. This helps during development, especially if you want this randomness for the interface.
I hope this defines the use case better and you see the value in this. |
@taylorotwell see above for a deeper example/use case. |
@taylorotwell @derpoho It would be really useful for me. I am using a Factory sequence to alternate between different types of relations. |
Yeah I ended up having the same requirement today, it's nice to mockup and test some stuff, I manually modified the vendor folder, would be sweet to get this merged honestly |
@taylorotwell is too busy ;) Maybe it will come up some time again. |
Often one needs some randomness in generating Factories for the development environment. For this case the count method in the Factory Base class should accept a callable in addition to int or null. It's optional to be used by developers and i think it has no breaking changes or follow up problems - at least i cannot think of anything.
What could be done with this addition?
Hope this is of interest!