Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.1 - Organising Factories

This seems like it should be a fairly simply question, but with Laravels (5.1) model factories, am I supposed to place every model definition inside the one ModelFactory.php file?

If, for example, I have 200 different models, I can see this file (Database\Factories\ModelFactory.php) getting very large and cluttered.

My question is:

Is there a better way to organise model factories, or should I really define them all in that one file? What is best practice?

like image 902
Phil Cross Avatar asked Nov 16 '15 15:11

Phil Cross


1 Answers

If you have a look at the source code you can see that it takes the path (/factories) and requires every single file. So you can definitely create as many files as you want in that directory and separate them by concern or model.

like image 176
Karl Laurentius Roos Avatar answered Sep 30 '22 17:09

Karl Laurentius Roos