Skip to content
Advertisement

Laravel seeder for table that is hardcoded

I have several tables in my database that are simply used for reference in my application.

For example, a table that has two columns, State and State Abbreviation, and has all 50 states and their abbreviations as rows.

JavaScript

I want to write seeders for these tables in Laravel, since I want these tables to exist when I start a new version of the application.

What is the best way of storing this data and creating these seeders?

Advertisement

Answer

Seeders are for more than just test data — and they are perfect for static data.

It won’t take too long to just manually create the seeder, but instead of rebuilding the wheel, you can use this courtesy of ggoforth: https://github.com/ggoforth/laravel-5-us-states-seeder/blob/master/StatesSeeder.php

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement