Using the Generators package to set up an app
Generators
is a popular Laravel package that automates quite a bit of file creation. In addition to controllers
and models
, it can also generate views
, migrations
, seeds
, and more, all through a command-line interface.
Getting ready
For this recipe, we'll be using the Laravel 4 Generators package maintained by Jeffrey Way that was installed in the Downloading and installing packages recipe. We'll also need a properly configured MySQL database.
How to do it…
Follow these steps for this recipe:
Open the command line in the root of our app and, using the generator, create a scaffold for our cities as follows:
php artisan generate:scaffold cities --fields="city:string"
In the command line, create a scaffold for our superheroes as follows:
php artisan generate:scaffold superheroes --fields="name:string, city_id:integer:unsigned"
In our project, look in the
app/database/seeds
directory and find a file namedCitiesTableSeeder.php
. Open it and add some...