Search code examples
ooplaravelsingle-responsibility-principleseeding

Pull mass name list from database or in script?


I need to fill an input box with a first name and last name. The user will press "Randomize" and it will pull a random first and last name and fill the inputs.

My question is I'm not sure if I should put the names in tables (firstNames, lastNames) or just store them in a javascript file and pull straight from that.

I'm trying to follow the Single Responsibility Principle so I'm inclined to choose the former, but then I have two more models, two more seeders, two more tables, and probably a class to pull all that together. And then do I fill from a CSV file or just from a manually populated seeder? It seems like a lot of work and extra files for a 1-time use.

I know I'll get crap for this being an opinion based question but there is no one or where else to ask.

Also if you know of a place to ask these kind of questions that won't get me ripped apart I'd appreciate that.


Solution

  • I would suggest using the Faker PHP library. That way you wouldn't have to create extra tables, models, or have to worry about finding yourself fake data.

    To install it in your project, simply add the dependency in your composer.json file. and run a composer update.

    "require-dev": {
      "fzaninotto/faker": "1.3.*@dev"
    },
    

    Then you can use it to create fake first and last names for you (in your controller most likely)

    $faker = Faker\Factory::create();
    
    $firstName = $faker->firstName;
    $lastName = $faker->lastName;
    

    Edit:

    To add your own names you can either edit or override the name provider file located here.