From fa49a9fd11c365ca7e7a5d6ea9942d06d1bf4293 Mon Sep 17 00:00:00 2001 From: Gaurav Deshpande <93gaurav93@gmail.com> Date: Sun, 29 Apr 2018 17:15:38 +0530 Subject: [PATCH] Fix - foreign constraints doc --- readme.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/readme.md b/readme.md index 9f3fc4e..0081ae8 100644 --- a/readme.md +++ b/readme.md @@ -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'); ``` @@ -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');