Download the PHP package amestsantim/generators without Composer
On this page you can find all versions of the php package amestsantim/generators. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download amestsantim/generators
More information about amestsantim/generators
Files in amestsantim/generators
Package generators
Short Description Extend Laravel 5's generators (fork of laracasts/generators)
License MIT
Informations about the package generators
Laravel 5 Extended Generators
Important: This is a fork of the Laravel-5-Generators-Extended repo forked for the purpose of merging a long time open pull request that adds an optional --path parameter. I have also edited the migration stub and removed the id and timestamp fields added by default. I have added a --timestamps switch to control the timestamps. I have also added a --foreignReferenceName= option to pass in the name of the id column on the referenced table, if you need it to be different from the default of 'id'
If you're familiar with my Laravel 4 Generators, then this is basically the same thing - just upgraded for Laravel 5.
L5 includes a bunch of generators out of the box, so this package only needs to add a few things, like:
make:migration:schema
make:migration:pivot
make:seed
With one or two more to come.
Usage on Laravel 5.5
Step 1: Install Through Composer
Step 2: Run Artisan!
You're all set. Run php artisan
from the console, and you'll see the new commands in the make:*
namespace section.
Usage on Laravel 5.4 and 5.3
Step 1: Install Through Composer
Step 2: Add the Service Provider
You'll only want to use these generators for local development, so you don't want to update the production providers
array in config/app.php
. Instead, add the provider in app/Providers/AppServiceProvider.php
, like so:
Step 3: Run Artisan!
You're all set. Run php artisan
from the console, and you'll see the new commands in the make:*
namespace section.
Examples
- Migrations With Schema
- Pivot Tables
- Database Seeders
Migrations With Schema
Notice the format that we use, when declaring any applicable schema: a comma-separate list...
So any of these will do:
Using the schema from earlier...
...this will give you:
When generating migrations with schema, the name of your migration (like, "create_users_table") matters. We use it to figure out what you're trying to accomplish. In this case, we began with the "create" keyword, which signals that we want to create a new table.
Alternatively, we can use the "remove" or "add" keywords, and the generated boilerplate will adapt, as needed. Let's create a migration to remove a column.
Now, notice that we're using the correct Schema methods.
Here's a few other examples of commands that you might write:
php artisan make:migration:schema create_posts_table
php artisan make:migration:schema create_posts_table --schema="title:string, body:text, excerpt:string:nullable"
php artisan make:migration:schema remove_excerpt_from_posts_table --schema="excerpt:string:nullable"
Now, when you create a migration, you typically want a model to go with it, right? By default, we'll go ahead and create an Eloquent model to go with your migration. This means, if you run, say:
You'll get a migration, populated with the schema...but you'll also get an Eloquent model at app/Dog.php
. Naturally, you can opt out of this by adding the --model=0
flag/option.
If you wish to specify a different path for your migration file, you can use the --path
option like so:
Foreign Constraints
There's also a secret bit of sugar for when you need to generate foreign constraints. Imagine that you have a posts table, where each post belongs to a user. Let's try:
Notice that "foreign" option (user_id:unsignedInteger:foreign
)? That's special. It signals that user_id
should receive a foreign constraint. Following conventions, this will give us:
As such, for that full command, our schema should look like so:
Neato.
Pivot Tables
So you need a migration to setup a pivot table in your database? Easy. We can scaffold the whole class with a single command.
Here we pass, in any order, the names of the two tables that we need a joining/pivot table for. This will give you:
Notice that the naming conventions are being followed here, regardless of what order you pass the table names.
Database Seeders
This one is fairly basic. It just gives you a quick seeder class in the "database/seeds" folder.