From 8a890e1e5eb9744ae0bb486571f726ab89f7c5cf Mon Sep 17 00:00:00 2001
From: Fahry Ibrahim <fahryibrahim06@gmail.com>
Date: Sun, 25 Aug 2024 14:40:47 +0700
Subject: [PATCH 01/13] task-1

---
 .../task1/2021_11_08_091231_create_tasks_table.php          | 3 +--
 .../task1/2021_11_08_092943_create_comments_table.php       | 6 ++----
 2 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/database/migrations/task1/2021_11_08_091231_create_tasks_table.php b/database/migrations/task1/2021_11_08_091231_create_tasks_table.php
index 08bf628f..d249f4b7 100644
--- a/database/migrations/task1/2021_11_08_091231_create_tasks_table.php
+++ b/database/migrations/task1/2021_11_08_091231_create_tasks_table.php
@@ -15,8 +15,7 @@ public function up()
     {
         Schema::create('tasks', function (Blueprint $table) {
             $table->id();
-            $table->bigInteger('user_id');
-            $table->foreign('user_id')->references('id')->on('users');
+            $table->foreignId('user_id')->constrained();
             $table->string('name');
             $table->timestamps();
         });
diff --git a/database/migrations/task1/2021_11_08_092943_create_comments_table.php b/database/migrations/task1/2021_11_08_092943_create_comments_table.php
index 0378294b..3c5ff32a 100644
--- a/database/migrations/task1/2021_11_08_092943_create_comments_table.php
+++ b/database/migrations/task1/2021_11_08_092943_create_comments_table.php
@@ -15,10 +15,8 @@ public function up()
     {
         Schema::create('comments', function (Blueprint $table) {
             $table->id();
-            $table->unsignedInteger('user_id');
-            $table->foreign('user_id')->references('id')->on('users');
-            $table->unsignedInteger('comment_id');
-            $table->foreign('comment_id')->references('id')->on('comments');
+            $table->foreignId('user_id')->constrained();
+            $table->foreignId('comment_id')->constrained();
             $table->string('comment_text');
             $table->timestamps();
         });

From 4798d9c22192493d7dc180bb10b8902d87d9bffb Mon Sep 17 00:00:00 2001
From: Fahry Ibrahim <fahryibrahim06@gmail.com>
Date: Sun, 25 Aug 2024 14:51:14 +0700
Subject: [PATCH 02/13] task-2

---
 .../task2/2021_11_09_075928_add_surname_to_users_table.php     | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/database/migrations/task2/2021_11_09_075928_add_surname_to_users_table.php b/database/migrations/task2/2021_11_09_075928_add_surname_to_users_table.php
index 5a3422a4..9dccb6cc 100644
--- a/database/migrations/task2/2021_11_09_075928_add_surname_to_users_table.php
+++ b/database/migrations/task2/2021_11_09_075928_add_surname_to_users_table.php
@@ -16,6 +16,7 @@ public function up()
         Schema::table('users', function (Blueprint $table) {
             // TASK: Add a string field "surname" which would go after the field "name"
             // Write code here
+            $table->string('surname')->after('name');
         });
     }
 
@@ -27,7 +28,7 @@ public function up()
     public function down()
     {
         Schema::table('users', function (Blueprint $table) {
-            //
+            $table->dropColumn('surname');
         });
     }
 }

From 222a2a68cb3b57a244518c7d20fe32711eb7afad Mon Sep 17 00:00:00 2001
From: Fahry Ibrahim <fahryibrahim06@gmail.com>
Date: Sun, 25 Aug 2024 14:58:28 +0700
Subject: [PATCH 03/13] Task-3

---
 .../migrations/task3/2021_11_09_080955_create_projects_table.php | 1 +
 1 file changed, 1 insertion(+)

diff --git a/database/migrations/task3/2021_11_09_080955_create_projects_table.php b/database/migrations/task3/2021_11_09_080955_create_projects_table.php
index 9dc9d7b5..3cbcc04d 100644
--- a/database/migrations/task3/2021_11_09_080955_create_projects_table.php
+++ b/database/migrations/task3/2021_11_09_080955_create_projects_table.php
@@ -19,6 +19,7 @@ public function up()
             $table->timestamps();
 
             // TASK: Add soft deletes column here
+            $table->softDeletes();
         });
     }
 

From 820e72652d054852665ef3840018fe7fd1f30c67 Mon Sep 17 00:00:00 2001
From: Fahry Ibrahim <fahryibrahim06@gmail.com>
Date: Sun, 25 Aug 2024 15:03:07 +0700
Subject: [PATCH 04/13] Task-4

---
 .../task4/2021_11_09_082205_create_products_table.php           | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/database/migrations/task4/2021_11_09_082205_create_products_table.php b/database/migrations/task4/2021_11_09_082205_create_products_table.php
index 78636019..6d48703a 100644
--- a/database/migrations/task4/2021_11_09_082205_create_products_table.php
+++ b/database/migrations/task4/2021_11_09_082205_create_products_table.php
@@ -16,7 +16,7 @@ public function up()
         // TASK: Edit this file, so that deleting category would auto-delete its products
         Schema::create('products', function (Blueprint $table) {
             $table->id();
-            $table->foreignId('category_id')->constrained();
+            $table->foreignId('category_id')->constrained()->onDelete('cascade');
             $table->string('name');
             $table->timestamps();
         });

From e7a6246824dfc53ab409c370299ed6a97c33d393 Mon Sep 17 00:00:00 2001
From: Fahry Ibrahim <fahryibrahim06@gmail.com>
Date: Sun, 25 Aug 2024 15:09:08 +0700
Subject: [PATCH 05/13] Task-5

---
 .../task5/2021_11_09_083121_update_users_table.php        | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/database/migrations/task5/2021_11_09_083121_update_users_table.php b/database/migrations/task5/2021_11_09_083121_update_users_table.php
index c10976a5..6a996e2a 100644
--- a/database/migrations/task5/2021_11_09_083121_update_users_table.php
+++ b/database/migrations/task5/2021_11_09_083121_update_users_table.php
@@ -14,9 +14,11 @@ class UpdateUsersTable extends Migration
     public function up()
     {
         // TASK: add an if-statement in this file to NOT add column if it already exists
-        Schema::table('users', function (Blueprint $table) {
-            $table->string('name');
-        });
+        if (Schema::hasTable('users')) {
+            Schema::table('users', function (Blueprint $table) {
+                $table->string('name');
+            });
+        }
     }
 
     /**

From 99a8773a9c4db9225cbc1a0130d40b12b7b916b6 Mon Sep 17 00:00:00 2001
From: Fahry Ibrahim <fahryibrahim06@gmail.com>
Date: Sun, 25 Aug 2024 15:11:25 +0700
Subject: [PATCH 06/13] Task-6

---
 .../task6/2021_11_09_083843_create_companies_table.php          | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/database/migrations/task6/2021_11_09_083843_create_companies_table.php b/database/migrations/task6/2021_11_09_083843_create_companies_table.php
index 9554406a..360998bb 100644
--- a/database/migrations/task6/2021_11_09_083843_create_companies_table.php
+++ b/database/migrations/task6/2021_11_09_083843_create_companies_table.php
@@ -16,7 +16,7 @@ public function up()
         // TASK: edit this migration so there couldn't be two companies with the same name
         Schema::create('companies', function (Blueprint $table) {
             $table->id();
-            $table->string('name');
+            $table->string('name')->unique();
             $table->timestamps();
         });
     }

From 1d470a3352ce35f90b690c1193a94998022f047f Mon Sep 17 00:00:00 2001
From: Fahry Ibrahim <fahryibrahim06@gmail.com>
Date: Sun, 25 Aug 2024 15:17:42 +0700
Subject: [PATCH 07/13] Task-7

---
 .../task7/2021_11_09_084922_create_new_companies_table.php      | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/database/migrations/task7/2021_11_09_084922_create_new_companies_table.php b/database/migrations/task7/2021_11_09_084922_create_new_companies_table.php
index 868a2422..36bf0166 100644
--- a/database/migrations/task7/2021_11_09_084922_create_new_companies_table.php
+++ b/database/migrations/task7/2021_11_09_084922_create_new_companies_table.php
@@ -17,7 +17,7 @@ public function up()
         // its automatic value of name would be "My company"
         Schema::create('companies', function (Blueprint $table) {
             $table->id();
-            $table->string('name');
+            $table->string('name')->default('My company');
             $table->timestamps();
         });
     }

From b35653ad5f72d00852b3689b2f4ab2ab0f2711ab Mon Sep 17 00:00:00 2001
From: Fahry Ibrahim <fahryibrahim06@gmail.com>
Date: Sun, 25 Aug 2024 15:19:57 +0700
Subject: [PATCH 08/13] Task-8

---
 .../task8/2021_11_09_085453_rename_companies_table.php           | 1 +
 1 file changed, 1 insertion(+)

diff --git a/database/migrations/task8/2021_11_09_085453_rename_companies_table.php b/database/migrations/task8/2021_11_09_085453_rename_companies_table.php
index dc4ae6f2..19547c02 100644
--- a/database/migrations/task8/2021_11_09_085453_rename_companies_table.php
+++ b/database/migrations/task8/2021_11_09_085453_rename_companies_table.php
@@ -14,6 +14,7 @@ class RenameCompaniesTable extends Migration
     public function up()
     {
         // TASK: add a migration to rename table "company" into "companies"
+        $table->rename('company', 'companies');
     }
 
     /**

From 69042fe5c5d6a2fa525ed888a0e813432af58992 Mon Sep 17 00:00:00 2001
From: Fahry Ibrahim <fahryibrahim06@gmail.com>
Date: Sun, 25 Aug 2024 15:21:25 +0700
Subject: [PATCH 09/13] Task-9

---
 .../task9/2021_11_09_090018_rename_name_in_companies_table.php   | 1 +
 1 file changed, 1 insertion(+)

diff --git a/database/migrations/task9/2021_11_09_090018_rename_name_in_companies_table.php b/database/migrations/task9/2021_11_09_090018_rename_name_in_companies_table.php
index f270c9e7..6714d010 100644
--- a/database/migrations/task9/2021_11_09_090018_rename_name_in_companies_table.php
+++ b/database/migrations/task9/2021_11_09_090018_rename_name_in_companies_table.php
@@ -16,6 +16,7 @@ public function up()
         // TASK: write the migration to rename the column "title" into "name"
         Schema::table('companies', function (Blueprint $table) {
             // Write code here
+            $table->renameColumn('title', 'name');
         });
     }
 

From e7a03c733b06c707a8042ae4df39b9c97e49b186 Mon Sep 17 00:00:00 2001
From: Fahry Ibrahim <fahryibrahim06@gmail.com>
Date: Sun, 25 Aug 2024 15:24:09 +0700
Subject: [PATCH 10/13] Task-10

---
 .../task10/2021_11_09_090858_create_visitors_table.php          | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/database/migrations/task10/2021_11_09_090858_create_visitors_table.php b/database/migrations/task10/2021_11_09_090858_create_visitors_table.php
index 7a53968c..08e7516e 100644
--- a/database/migrations/task10/2021_11_09_090858_create_visitors_table.php
+++ b/database/migrations/task10/2021_11_09_090858_create_visitors_table.php
@@ -16,7 +16,7 @@ public function up()
         // TASK: edit this migration so country_id would allow NULL values
         Schema::create('visitors', function (Blueprint $table) {
             $table->id();
-            $table->foreignId('country_id')->constrained();
+            $table->foreignId('country_id')->nullable()->constrained();
             $table->string('ip_address');
             $table->timestamps();
         });

From 5a9ae1cd9ee577d6b8b74b92d43b5776cea501e5 Mon Sep 17 00:00:00 2001
From: Fahry Ibrahim <fahryibrahim06@gmail.com>
Date: Sun, 25 Aug 2024 15:30:26 +0700
Subject: [PATCH 11/13] refactor: fix task-5 and task-8

---
 .../2021_11_09_083121_update_users_table.php  |  2 +-
 ...2021_11_09_083225_recreate_users_table.php | 20 ++++++++++---------
 ...21_11_09_085453_rename_companies_table.php |  2 +-
 3 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/database/migrations/task5/2021_11_09_083121_update_users_table.php b/database/migrations/task5/2021_11_09_083121_update_users_table.php
index 6a996e2a..ff98ea0d 100644
--- a/database/migrations/task5/2021_11_09_083121_update_users_table.php
+++ b/database/migrations/task5/2021_11_09_083121_update_users_table.php
@@ -14,7 +14,7 @@ class UpdateUsersTable extends Migration
     public function up()
     {
         // TASK: add an if-statement in this file to NOT add column if it already exists
-        if (Schema::hasTable('users')) {
+        if (Schema::hasColumn('name')) {
             Schema::table('users', function (Blueprint $table) {
                 $table->string('name');
             });
diff --git a/database/migrations/task5/2021_11_09_083225_recreate_users_table.php b/database/migrations/task5/2021_11_09_083225_recreate_users_table.php
index 6b15a7c6..5d35cc93 100644
--- a/database/migrations/task5/2021_11_09_083225_recreate_users_table.php
+++ b/database/migrations/task5/2021_11_09_083225_recreate_users_table.php
@@ -14,15 +14,17 @@ class RecreateUsersTable extends Migration
     public function up()
     {
         // TASK: add an if-statement in this file to NOT create table if it already exists
-        Schema::create('users', function (Blueprint $table) {
-            $table->id();
-            $table->string('name');
-            $table->string('email')->unique();
-            $table->timestamp('email_verified_at')->nullable();
-            $table->string('password');
-            $table->rememberToken();
-            $table->timestamps();
-        });
+        if (Schema::hasTable('users')) {
+            Schema::create('users', function (Blueprint $table) {
+                $table->id();
+                $table->string('name');
+                $table->string('email')->unique();
+                $table->timestamp('email_verified_at')->nullable();
+                $table->string('password');
+                $table->rememberToken();
+                $table->timestamps();
+            });
+        }
     }
 
     /**
diff --git a/database/migrations/task8/2021_11_09_085453_rename_companies_table.php b/database/migrations/task8/2021_11_09_085453_rename_companies_table.php
index 19547c02..7468f47e 100644
--- a/database/migrations/task8/2021_11_09_085453_rename_companies_table.php
+++ b/database/migrations/task8/2021_11_09_085453_rename_companies_table.php
@@ -14,7 +14,7 @@ class RenameCompaniesTable extends Migration
     public function up()
     {
         // TASK: add a migration to rename table "company" into "companies"
-        $table->rename('company', 'companies');
+        Schema::rename('company', 'companies');
     }
 
     /**

From f848c2e6a74f0c1baba1c3f27e6bdade760f7ea4 Mon Sep 17 00:00:00 2001
From: Fahry Ibrahim <fahryibrahim06@gmail.com>
Date: Sun, 25 Aug 2024 15:33:18 +0700
Subject: [PATCH 12/13] refactor: fix task-5

---
 .../migrations/task5/2021_11_09_083121_update_users_table.php   | 2 +-
 .../migrations/task5/2021_11_09_083225_recreate_users_table.php | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/database/migrations/task5/2021_11_09_083121_update_users_table.php b/database/migrations/task5/2021_11_09_083121_update_users_table.php
index ff98ea0d..259c5997 100644
--- a/database/migrations/task5/2021_11_09_083121_update_users_table.php
+++ b/database/migrations/task5/2021_11_09_083121_update_users_table.php
@@ -14,7 +14,7 @@ class UpdateUsersTable extends Migration
     public function up()
     {
         // TASK: add an if-statement in this file to NOT add column if it already exists
-        if (Schema::hasColumn('name')) {
+        if (!Schema::hasColumn('name')) {
             Schema::table('users', function (Blueprint $table) {
                 $table->string('name');
             });
diff --git a/database/migrations/task5/2021_11_09_083225_recreate_users_table.php b/database/migrations/task5/2021_11_09_083225_recreate_users_table.php
index 5d35cc93..fac77cb2 100644
--- a/database/migrations/task5/2021_11_09_083225_recreate_users_table.php
+++ b/database/migrations/task5/2021_11_09_083225_recreate_users_table.php
@@ -14,7 +14,7 @@ class RecreateUsersTable extends Migration
     public function up()
     {
         // TASK: add an if-statement in this file to NOT create table if it already exists
-        if (Schema::hasTable('users')) {
+        if (!Schema::hasTable('users')) {
             Schema::create('users', function (Blueprint $table) {
                 $table->id();
                 $table->string('name');

From dc8cbe15836b2476340043b6ddf887f273ed595d Mon Sep 17 00:00:00 2001
From: Fahry Ibrahim <fahryibrahim06@gmail.com>
Date: Sun, 25 Aug 2024 15:34:52 +0700
Subject: [PATCH 13/13] refactor: fixing the hasColumn method

---
 .../migrations/task5/2021_11_09_083121_update_users_table.php   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/database/migrations/task5/2021_11_09_083121_update_users_table.php b/database/migrations/task5/2021_11_09_083121_update_users_table.php
index 259c5997..7bac3981 100644
--- a/database/migrations/task5/2021_11_09_083121_update_users_table.php
+++ b/database/migrations/task5/2021_11_09_083121_update_users_table.php
@@ -14,7 +14,7 @@ class UpdateUsersTable extends Migration
     public function up()
     {
         // TASK: add an if-statement in this file to NOT add column if it already exists
-        if (!Schema::hasColumn('name')) {
+        if (!Schema::hasColumn('users','name')) {
             Schema::table('users', function (Blueprint $table) {
                 $table->string('name');
             });