Were all fields added to the database after migrating, what errors? Where are other fields like password?
Jan 7, 2023
15
Level 3
Adding new profile fields but not updating the database
Yet again running into problems with developing my platform :)
Now I am trying to add new fields to platform user profiles but after doing all tasks (I guess) right, the database is not getting populated with them.
What are the normal steps I have to do to add new fields? I added a new migration:
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->string('username')->nullable();
$table->longText('description')->nullable()->default('text');
$table->text('siteweb')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('username');
$table->dropColumn('description');
$table->dropColumn('siteweb');
});
}
};
Then I edited the profile controller:
$request->validate([
'username' => ['required', 'text', 'max:255'],
'description' => ['required', 'text', 'max:255'],
'siteweb' => ['required', 'url', 'max:255'],
'avatar' => 'required|image',
]);
After that I edited the user model:
protected $fillable = [
'name',
'username',
'email',
'password',
'avatar',
'username',
'descriprion',
'siteweb',
];
Then edited my blade form:
<form method="post" action="{{ route('profile.update') }}" class="mt-6 space-y-6">
@csrf
@method('patch')
<div>
<x-input-label for="username" :value="__('Nume Utilizator')" />
<x-text-input id="username" name="username" type="text" class="mt-1 block w-full" :value="old('username', $user->username)" autocomplete="username" />
<x-input-error class="mt-2" :messages="$errors->get('username')" />
</div>
<div>
<x-input-label for="description" :value="__('Descriere Personală')" />
<x-text-input id="description" name="description" type="text" class="mt-1 block w-full" :value="old('description', $user->description)" autocomplete="description" />
<x-input-error class="mt-2" :messages="$errors->get('description')" />
</div>
<div>
<x-input-label for="siteweb" :value="__('Site Personal')" />
<x-text-input id="siteweb" name="siteweb" type="url" class="mt-1 block w-full" :value="old('siteweb', $user->username)" autocomplete="siteweb" />
<x-input-error class="mt-2" :messages="$errors->get('siteweb')" />
</div>
<div class="flex items-center gap-4">
<x-primary-button>{{ __('Salvează') }}</x-primary-button>
@if (session('status') === 'profile-updated')
<p
x-data="{ show: true }"
x-show="show"
x-transition
x-init="setTimeout(() => show = false, 5000)"
class="text-sm text-gray-600"
>{{ __('Setări salvate!') }}</p>
@endif
</div>
</form>
Please tell me what I'm doing wrong...
Please or to participate in this conversation.