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
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();
});
@@ -16,6 +16,7 @@ class AddSurnameToUsersTable extends Migration
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');
});
}
@@ -19,6 +19,7 @@ class CreateProjectsTable extends Migration
$table->timestamps();
// 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
Schema::create('products', function (Blueprint $table) {
$table->id();
$table->foreignId('category_id')->constrained();
$table->foreignId('category_id')->constrained()->onUpdate('cascade')->onDelete('cascade');
$table->string('name');
$table->timestamps();
});
@@ -14,9 +14,12 @@ 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('users', 'name')) {
Schema::table('users', function (Blueprint $table) {
$table->string('name');
});
}
}
/**
@@ -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();
});
}
}
/**
@@ -16,7 +16,7 @@ class CreateCompaniesTable extends Migration
// 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();
});
}
@@ -17,7 +17,7 @@ class CreateNewCompaniesTable extends Migration
// 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();
});
}
@@ -14,6 +14,7 @@ class RenameCompaniesTable extends Migration
public function up()
{
// 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"
Schema::table('companies', function (Blueprint $table) {
// Write code here
$table->renameColumn('title', 'name');
});
}