How to turn off casting during seeding?
I do find the $casts causing me troubles during development and constant reseeding .
I have this:
but it causes issues when I import stuff from my csv file and the quotes and [ are messed up.
If I comment it off:
. it will be imported from the csv as it should.
But then I have to manually uncomment the casting in the model so the tables and forms reflect and read the values. Otherwise, for example, the columns will be empty or the form select field will look like nothing is selected.
So, because of this procedure I sometimes I forget to do it in the correct order and the csv file is big so it is getting frustrating.
Is there a way I could use a seeding specific $casting and a normal usage casting somehow left alone - without the need to comment before importing and uncomment after importing?
For example can I overwrite the model's casting setting in the seeder file?
4 Replies
How Do you Seed ?
$this->call(... and seeder classes here)
Solution
via eleoquent i guess so try something like this:
Ok, interesting.
I am using Car::create(...
and then array of things I want to store)
so I will try setRawAttributes
and report back
great! Seems to be working nice. Thank you