complete all tasks

This commit is contained in:
Thuan Bui
2025-04-04 08:29:01 +09:00
parent e23f3b49a8
commit 77f696bcb7
10 changed files with 22 additions and 13 deletions
@@ -16,7 +16,7 @@ class CreateVisitorsTable extends Migration
// TASK: edit this migration so country_id would allow NULL values // TASK: edit this migration so country_id would allow NULL values
Schema::create('visitors', function (Blueprint $table) { Schema::create('visitors', function (Blueprint $table) {
$table->id(); $table->id();
$table->foreignId('country_id')->constrained(); $table->foreignId('country_id')->nullable()->constrained();
$table->string('ip_address'); $table->string('ip_address');
$table->timestamps(); $table->timestamps();
}); });
@@ -16,6 +16,7 @@ class AddSurnameToUsersTable extends Migration
Schema::table('users', function (Blueprint $table) { Schema::table('users', function (Blueprint $table) {
// TASK: Add a string field "surname" which would go after the field "name" // TASK: Add a string field "surname" which would go after the field "name"
// Write code here // Write code here
$table->string('surname')->after('name');
}); });
} }
@@ -19,6 +19,7 @@ class CreateProjectsTable extends Migration
$table->timestamps(); $table->timestamps();
// TASK: Add soft deletes column here // TASK: Add soft deletes column here
$table->softDeletes();
}); });
} }
@@ -16,7 +16,7 @@ class CreateProductsTable extends Migration
// TASK: Edit this file, so that deleting category would auto-delete its products // TASK: Edit this file, so that deleting category would auto-delete its products
Schema::create('products', function (Blueprint $table) { Schema::create('products', function (Blueprint $table) {
$table->id(); $table->id();
$table->foreignId('category_id')->constrained(); $table->foreignId('category_id')->constrained()->onUpdate('cascade')->onDelete('cascade');
$table->string('name'); $table->string('name');
$table->timestamps(); $table->timestamps();
}); });
@@ -14,9 +14,12 @@ class UpdateUsersTable extends Migration
public function up() public function up()
{ {
// TASK: add an if-statement in this file to NOT add column if it already exists // TASK: add an if-statement in this file to NOT add column if it already exists
if (! Schema::hasColumn('users', 'name')) {
Schema::table('users', function (Blueprint $table) { Schema::table('users', function (Blueprint $table) {
$table->string('name'); $table->string('name');
}); });
}
} }
/** /**
@@ -14,15 +14,17 @@ class RecreateUsersTable extends Migration
public function up() public function up()
{ {
// TASK: add an if-statement in this file to NOT create table if it already exists // TASK: add an if-statement in this file to NOT create table if it already exists
Schema::create('users', function (Blueprint $table) { if (! Schema::hasTable('users')) {
$table->id(); Schema::create('users', function (Blueprint $table) {
$table->string('name'); $table->id();
$table->string('email')->unique(); $table->string('name');
$table->timestamp('email_verified_at')->nullable(); $table->string('email')->unique();
$table->string('password'); $table->timestamp('email_verified_at')->nullable();
$table->rememberToken(); $table->string('password');
$table->timestamps(); $table->rememberToken();
}); $table->timestamps();
});
}
} }
/** /**
@@ -16,7 +16,7 @@ class CreateCompaniesTable extends Migration
// TASK: edit this migration so there couldn't be two companies with the same name // TASK: edit this migration so there couldn't be two companies with the same name
Schema::create('companies', function (Blueprint $table) { Schema::create('companies', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('name'); $table->string('name')->unique();
$table->timestamps(); $table->timestamps();
}); });
} }
@@ -17,7 +17,7 @@ class CreateNewCompaniesTable extends Migration
// its automatic value of name would be "My company" // its automatic value of name would be "My company"
Schema::create('companies', function (Blueprint $table) { Schema::create('companies', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('name'); $table->string('name')->default('My company');
$table->timestamps(); $table->timestamps();
}); });
} }
@@ -14,6 +14,7 @@ class RenameCompaniesTable extends Migration
public function up() public function up()
{ {
// TASK: add a migration to rename table "company" into "companies" // TASK: add a migration to rename table "company" into "companies"
Schema::rename('company', 'companies');
} }
/** /**
@@ -16,6 +16,7 @@ class RenameNameInCompaniesTable extends Migration
// TASK: write the migration to rename the column "title" into "name" // TASK: write the migration to rename the column "title" into "name"
Schema::table('companies', function (Blueprint $table) { Schema::table('companies', function (Blueprint $table) {
// Write code here // Write code here
$table->renameColumn('title', 'name');
}); });
} }