From 111e328e573b7569755749b48bc95e56a7a4213e Mon Sep 17 00:00:00 2001 From: MogahidGaffar Date: Sun, 1 Sep 2024 19:22:00 +0300 Subject: [PATCH 1/2] My test Attempt --- .env.example | 52 ------------------- .../2021_11_08_091231_create_tasks_table.php | 3 +- ...021_11_08_092943_create_comments_table.php | 4 +- ...021_11_09_090858_create_visitors_table.php | 2 +- ...1_09_075928_add_surname_to_users_table.php | 3 ++ ...021_11_09_080955_create_projects_table.php | 2 + ...021_11_09_082205_create_products_table.php | 2 +- .../2021_11_09_083121_update_users_table.php | 19 ++++--- ...2021_11_09_083225_recreate_users_table.php | 20 +++---- ...21_11_09_083843_create_companies_table.php | 2 +- ...1_09_084922_create_new_companies_table.php | 2 +- ...21_11_09_085453_rename_companies_table.php | 1 + ..._090003_create_another_companies_table.php | 2 +- ..._090018_rename_name_in_companies_table.php | 3 +- 14 files changed, 37 insertions(+), 80 deletions(-) delete mode 100644 .env.example diff --git a/.env.example b/.env.example deleted file mode 100644 index 22c520a6..00000000 --- a/.env.example +++ /dev/null @@ -1,52 +0,0 @@ -APP_NAME=Laravel -APP_ENV=local -APP_KEY= -APP_DEBUG=true -APP_URL=http://localhost - -LOG_CHANNEL=stack -LOG_DEPRECATIONS_CHANNEL=null -LOG_LEVEL=debug - -DB_CONNECTION=mysql -DB_HOST=127.0.0.1 -DB_PORT=3306 -DB_DATABASE=project -DB_USERNAME=root -DB_PASSWORD= - -BROADCAST_DRIVER=log -CACHE_DRIVER=file -FILESYSTEM_DRIVER=local -QUEUE_CONNECTION=sync -SESSION_DRIVER=file -SESSION_LIFETIME=120 - -MEMCACHED_HOST=127.0.0.1 - -REDIS_HOST=127.0.0.1 -REDIS_PASSWORD=null -REDIS_PORT=6379 - -MAIL_MAILER=smtp -MAIL_HOST=mailhog -MAIL_PORT=1025 -MAIL_USERNAME=null -MAIL_PASSWORD=null -MAIL_ENCRYPTION=null -MAIL_FROM_ADDRESS=null -MAIL_FROM_NAME="${APP_NAME}" - -AWS_ACCESS_KEY_ID= -AWS_SECRET_ACCESS_KEY= -AWS_DEFAULT_REGION=us-east-1 -AWS_BUCKET= -AWS_USE_PATH_STYLE_ENDPOINT=false - -PUSHER_APP_ID= -PUSHER_APP_KEY= -PUSHER_APP_SECRET= -PUSHER_APP_CLUSTER=mt1 - -MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" -MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" 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..d62525a3 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->unsignedBigInteger('user_id')->foreign('user_id')->references('id')->on('users'); $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..4dc9d5e5 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->unsignedBigInteger('user_id')->foreign('user_id')->references('id')->on('users'); $table->unsignedInteger('comment_id'); - $table->foreign('comment_id')->references('id')->on('comments'); $table->string('comment_text'); $table->timestamps(); }); 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(); }); 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..e2b6cb82 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,9 @@ 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->after('name', function (Blueprint $table) { + $table->string('surname'); + }); }); } 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..ad35a32e 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 @@ -17,6 +17,8 @@ public function up() $table->id(); $table->string('name'); $table->timestamps(); + $table->softDeletes('deleted_at', precision: 0); + // TASK: Add soft deletes column here }); 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(); }); 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..8de362e9 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 @@ -10,14 +10,17 @@ class UpdateUsersTable extends Migration * Run the migrations. * * @return void - */ - 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'); - }); - } + */ + 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'); + }); + } + } /** * Reverse the migrations. 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..695f4391 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/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(); }); } 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(); }); } 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..86425725 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" + Schema::rename("company","companies"); } /** diff --git a/database/migrations/task9/2021_11_09_090003_create_another_companies_table.php b/database/migrations/task9/2021_11_09_090003_create_another_companies_table.php index 9b3dcf03..44cfe8d9 100644 --- a/database/migrations/task9/2021_11_09_090003_create_another_companies_table.php +++ b/database/migrations/task9/2021_11_09_090003_create_another_companies_table.php @@ -29,4 +29,4 @@ public function down() { Schema::dropIfExists('companies'); } -} +} \ No newline at end of file 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..3aaced87 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'); }); } @@ -30,4 +31,4 @@ public function down() // }); } -} +} \ No newline at end of file From e7bf6ae29e2b86d20af2824d6b701d75b7e19fd7 Mon Sep 17 00:00:00 2001 From: MogahidGaffar Date: Sun, 1 Sep 2024 19:23:50 +0300 Subject: [PATCH 2/2] My test Attempt --- .env | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 00000000..031dd572 --- /dev/null +++ b/.env @@ -0,0 +1,52 @@ +APP_NAME=Laravel +APP_ENV=local +APP_KEY=base64:fNGkWHnUlgbnTgCPUlz0pXdgK0Al2BUwTQMwPrUh0EM= +APP_DEBUG=true +APP_URL=http://localhost + +LOG_CHANNEL=stack +LOG_DEPRECATIONS_CHANNEL=null +LOG_LEVEL=debug + +DB_CONNECTION=mysql +DB_HOST=127.0.0.1 +DB_PORT=3306 +DB_DATABASE=mysql_testing +DB_USERNAME=root +DB_PASSWORD= + +BROADCAST_DRIVER=log +CACHE_DRIVER=file +FILESYSTEM_DRIVER=local +QUEUE_CONNECTION=sync +SESSION_DRIVER=file +SESSION_LIFETIME=120 + +MEMCACHED_HOST=127.0.0.1 + +REDIS_HOST=127.0.0.1 +REDIS_PASSWORD=null +REDIS_PORT=6379 + +MAIL_MAILER=smtp +MAIL_HOST=mailhog +MAIL_PORT=1025 +MAIL_USERNAME=null +MAIL_PASSWORD=null +MAIL_ENCRYPTION=null +MAIL_FROM_ADDRESS=null +MAIL_FROM_NAME="${APP_NAME}" + +AWS_ACCESS_KEY_ID= +AWS_SECRET_ACCESS_KEY= +AWS_DEFAULT_REGION=us-east-1 +AWS_BUCKET= +AWS_USE_PATH_STYLE_ENDPOINT=false + +PUSHER_APP_ID= +PUSHER_APP_KEY= +PUSHER_APP_SECRET= +PUSHER_APP_CLUSTER=mt1 + +MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" +MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"