Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vbasky's avatar

Create Nova User on custom User table

When I try to create my first nova user using

php artisan nova:user on my User table having an additional name field, nova squawks with an error

Column not found: 1054 Unknown column 'name' in 'field list'

My User table looks like this

id, role_id, username, firstname, lastname, email etc

How and where would I have to tell Nova that my User table has additional fields. Is there a migration for the nova:user that lets me customize ?

0 likes
8 replies
Ashraam's avatar

Not sure about that but did you update the basic User resource (in app/nova) to reflect your database structure ?

aurawindsurfing's avatar

Looks like you did not run migration correctly:

php artisan nova:install

php artisan migrate

if you would then there would ba a name column in there.

If however you want that table of yours then you can probably do it with a mutator and accessor on User model.

vbasky's avatar

I did and it has created a action_events table so the migration and installation was fine. I am able to login to nova dashboard if logged in as a user, but unable to create a nova user through the command due to the fact that my User table has additional fields

aurawindsurfing's avatar

Then you would need to overwrite this file:

vendor/nova/src/Nova.php

/**
     * Get the default callback used for creating new Nova users.
     *
     * @return \Closure
     */
    protected static function defaultCreateUserCallback()
    {
        return function ($name, $email, $password) {
            $guard = config('nova.guard') ?: config('auth.defaults.guard');

            $provider = config("auth.guards.{$guard}.provider");

            $model = config("auth.providers.{$provider}.model");

            return tap((new $model)->forceFill([
                'name' => $name,
                'email' => $email,
                'password' => Hash::make($password),
            ]))->save();
        };
    }
aurawindsurfing's avatar

Or try to do it while you save your model:

public static function boot()
    {
        parent::boot();

        static::saving(function ($user) {
            
            $name = explode(" ", $user->name);

            $user->firstname = $name[0];
            $user->lastname = $name[1];
            
        });
    }

but I would not consider this a good advice ;-)

ciberman's avatar

For someone coming from google. The best way to do it its to define a createUserUsing method in your NovaServiceProvider like this:


    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        parent::boot();

        Nova::createUserUsing(function($command) {
            return [
                $command->ask('Name'),
                $command->ask('Email Address'),
                $command->secret('Password'),
            ];
        }, function($name, $email, $password) {
            (new User)->forceFill([
                'name' => $name,
                'email' => $email,
                'password' => Hash::make($password),
                'email_verified_at' => now(),
                'activated_at' => now(), // my custom field
            ])->save();
        });
    }
4 likes
pnoeric's avatar

Same problem here-- Nova setup assumes the 'Users' table is configured a certain way. Mine isn't. ;-) Thanks @ciberman for the tip to set it up in Boot.

Please or to participate in this conversation.