Skip to content

Commit

Permalink
Merge pull request #156 from 93gaurav93/master
Browse files Browse the repository at this point in the history
Fix - foreign constraints in doc
  • Loading branch information
tabacitu authored May 7, 2018
2 parents 1aabd29 + fa49a9f commit 9c60662
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,13 @@ You'll get a migration, populated with the schema...but you'll also get an Eloqu
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:

```
php artisan make:migration:schema create_posts_table --schema="user_id:integer:foreign, title:string, body:text"
php artisan make:migration:schema create_posts_table --schema="user_id:unsignedInteger:foreign, title:string, body:text"
```

Notice that "foreign" option (`user_id:integer:foreign`)? That's special. It signals that `user_id` should receive a foreign constraint. Following conventions, this will give us:
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:

```
$table->integer('user_id');
$table->unsignedInteger('user_id');
$table->foreign('user_id')->references('id')->on('users');
```

Expand All @@ -207,7 +207,7 @@ As such, for that full command, our schema should look like so:
```
Schema::create('posts', function(Blueprint $table) {
$table->increments('id');
$table->integer('user_id');
$table->unsignedInteger('user_id');
$table->foreign('user_id')->references('id')->on('users');
$table->string('title');
$table->text('body');
Expand Down

0 comments on commit 9c60662

Please sign in to comment.