66
loading...
This website collects cookies to deliver better user experience
\resources\js\Pages\Profile\UpdateProfileInformationForm.vue
and locate the HTML code segment for the email field. Duplicate this code for the new field and replace the email keywords with the phone.<!-- Email -->
<div class="col-span-6 sm:col-span-4">
<jet-label for="email" value="Email" />
<jet-input id="email" type="email" class="mt-1 block w-full" v-model="form.email" />
<jet-input-error :message="form.errors.email" class="mt-2" />
</div>
<!-- Phone -->
<div class="col-span-6 sm:col-span-4">
<jet-label for="phone" value="Phone" />
<jet-input id="phone" type="text" class="mt-1 block w-full" v-model="form.phone" />
<jet-input-error :message="form.errors.phone" class="mt-2" />
</div>
phone: this.user.phone
below the email field line email: this.user.email
.data() {
return {
form: this.$inertia.form({
_method: 'PUT',
name: this.user.name,
email: this.user.email,
phone: this.user.phone,
photo: null,
}),
photoPreview: null,
}
},
npm run dev
command so that the changes in the javascript file are compiled. With this, the UI part of your task is done. You can now see the new field added to your profile section.php artisan
command to make a database migration file.php artisan make:migration add_phone_to_users --table="users"
up()
and down()
methods as below.<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddPhoneToUsers extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
//
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
//
});
}
}
up()
method like this:public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->string('phone')->after('email_verified_at')->nullable();
});
}
up()
method is called with the php artisan migrate
command and the field is added to the database table, as shown in the screenshot below:down()
method too, for rollback option.public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('phone');
});
}
down()
method is called with the php artisan migrate:rollback
command and the field is dropped from the database table.\app\Actions\Fortify\UpdateUserProfileInformation.php
file\app\Models\User.php
fileUpdateUserProfileInformation.php
file, we need to update two functions, update()
and updateVerifiedUser()
.update()
function, add the new field in two places, one in the validation array and the other in the array for the save function call as shown below.updateVerifiedUser
as shown below:app\Models\User.php
file./**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'email',
'password',
'phone',
];