-
-
Notifications
You must be signed in to change notification settings - Fork 273
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 macro for $this->translations()
in factories
#382
Conversation
Thanks! Could you also ad a test to make sure that this works. As for docs, I would add a page in the "Advanced" section, titled "Usage with factories". On this page, explain how you can use the macro in a few sentences, and provide a clear example. |
Yep, of course I can do that. I will write some documentation for this functionality. Currently I am quite busy with a family emergency, that might take a few weeks. |
This would be great, but it doesn't work, The macro produces this:
but when the factory is used in a seeder it will write the above string as a translation in it self, so the results in the database is the following:
|
Can you give me a code snippet for this? |
This is a basic example: Migration: create_elinks_table.php
ElinkFactory.php
Calling the factory from a seeder or from tinker like this: The result in the database is this:
|
BTW ths solution for the problem is very simple, don't return a json string, instead return an array in a format the
It works but I haven't done much testing |
Let me do some testing on your suggestion, returning an array might be the solution. |
@freekmurze I have added tests and docs :) |
All clear now. Nice! One final remark: could you rename |
Sure, I will rename. |
$this->translatable()
in factories$this->translations()
in factories
Thanks! |
Context
Because factory definitions do not go through a Model's accessors/mutators, old definitions break when migrating columns to use the translatable trait. This PR helps users overcome this hurdle, by adding a macro to the factory that outputs valid JSON for the translatable columns.
Proposal
This macro enables users to do the following in factory definitions, where
description
is a translatable column:Scenario 1:
Scenario 2:
Scenario 3:
The
translatable
function can also be used statically, usingFactory::translatable
Documentation
I would appreciate some guidance on the documentation, specifically what page this should be documented on.