Browse Source

Change column name from name to key

pull/68/head
Nafies Luthfi 5 years ago
parent
commit
751b9b3c4b
  1. 4
      app/Http/Controllers/UsersController.php
  2. 2
      database/migrations/2021_04_04_215601_create_user_metadata_table.php
  3. 8
      tests/Feature/UsersProfileTest.php

4
app/Http/Controllers/UsersController.php

@ -132,11 +132,11 @@ class UsersController extends Controller
$userAttributes = collect($userAttributes); $userAttributes = collect($userAttributes);
foreach (['cemetery_location_name', 'cemetery_location_address', 'cemetery_location_latitude', 'cemetery_location_longitude'] as $key) { foreach (['cemetery_location_name', 'cemetery_location_address', 'cemetery_location_latitude', 'cemetery_location_longitude'] as $key) {
if ($userAttributes->has($key)) { if ($userAttributes->has($key)) {
$userMeta = UserMetadata::where('name', $key)->firstOrNew();
$userMeta = UserMetadata::where('key', $key)->firstOrNew();
if (!$userMeta->exists) { if (!$userMeta->exists) {
$userMeta->id = Uuid::uuid4()->toString(); $userMeta->id = Uuid::uuid4()->toString();
$userMeta->user_id = $user->id; $userMeta->user_id = $user->id;
$userMeta->name = $key;
$userMeta->key = $key;
} }
$userMeta->value = $userAttributes->get($key); $userMeta->value = $userAttributes->get($key);
$userMeta->save(); $userMeta->save();

2
database/migrations/2021_04_04_215601_create_user_metadata_table.php

@ -16,7 +16,7 @@ class CreateUserMetadataTable extends Migration
Schema::create('user_metadata', function (Blueprint $table) { Schema::create('user_metadata', function (Blueprint $table) {
$table->uuid('id')->primary(); $table->uuid('id')->primary();
$table->foreignId('user_id')->constrained('users')->onDelete('cascade'); $table->foreignId('user_id')->constrained('users')->onDelete('cascade');
$table->string('name')->index();
$table->string('key')->index();
$table->text('value'); $table->text('value');
$table->timestamps(); $table->timestamps();
}); });

8
tests/Feature/UsersProfileTest.php

@ -191,25 +191,25 @@ class UsersProfileTest extends TestCase
$this->seeInDatabase('user_metadata', [ $this->seeInDatabase('user_metadata', [
'user_id' => $user->id, 'user_id' => $user->id,
'name' => 'cemetery_location_name',
'key' => 'cemetery_location_name',
'value' => 'Some name', 'value' => 'Some name',
]); ]);
$this->seeInDatabase('user_metadata', [ $this->seeInDatabase('user_metadata', [
'user_id' => $user->id, 'user_id' => $user->id,
'name' => 'cemetery_location_address',
'key' => 'cemetery_location_address',
'value' => 'Some address', 'value' => 'Some address',
]); ]);
$this->seeInDatabase('user_metadata', [ $this->seeInDatabase('user_metadata', [
'user_id' => $user->id, 'user_id' => $user->id,
'name' => 'cemetery_location_latitude',
'key' => 'cemetery_location_latitude',
'value' => '-3.333333', 'value' => '-3.333333',
]); ]);
$this->seeInDatabase('user_metadata', [ $this->seeInDatabase('user_metadata', [
'user_id' => $user->id, 'user_id' => $user->id,
'name' => 'cemetery_location_longitude',
'key' => 'cemetery_location_longitude',
'value' => '114.583333', 'value' => '114.583333',
]); ]);
} }

Loading…
Cancel
Save