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

charlieBrown's avatar

Unknown column 'id' in 'field list' - Laravel Notifications

I have been trying to understand why is this error appearing. This is my first time with Laravel's notification system and I'm getting the error above. I have been following the docummentation on Laravel's website but I can't seem to get the grip of this error.

JobDenied

    public function via($notifiable)
    {
        return ['database'];
    }
    public function toDatabase($notifiable)
    {
        return [
            'deniedTime'    => Carbon::now()
        ];
    }
    public function toArray($notifiable)
    {
        return [
            //
        ];
    }

Notification tables

// Generate using php artisan notifications:table
Schema::create('notifications', function (Blueprint $table) {
            $table->uuid('id')->primary();
            $table->string('type');
            $table->morphs('php ');
            $table->text('data');
            $table->timestamp('read_at')->nullable();
            $table->timestamps();
        });

Invonking the notification

$sendToUser  = User::find(2);
$sendToUser->notify(new JobDenied());

Any thoughts? I have no idea how to debug this

0 likes
4 replies
zachleigh's avatar

What does your User table look like? Is there any more to that message, like a stack trace or raw SQL query?

charlieBrown's avatar

Thank you @zacleigh for the answer. My users tableas follow:

$table->increments('id');
            $table->string('name');
            $table->string('last_name');
            $table->string('profile_picture')->default('default.jpg');
            $table->string('userProfile', 100)->default('')->unique();
            $table->enum('type', ['worker', 'employer']);
            $table->integer('concelho_id')->unsigned();
            $table->string('about', 500)->default('...');
            $table->string('email')->unique();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();

            /*
             * Indexes
             */
            $table->index('userProfile');
            $table->index('id');

The stacktrace is as follow:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'notifiable_id' in 'field list' (SQL: insert into `notifications` (`id`, `type`, `data`, `read_at`, `notifiable_id`, `notifiable_type`, `updated_at`, `created_at`) values (8889540e-b9df-4036-8d71-6f8fee63352f, App\Notifications\JobDenied, {"deniedTime":{"date":"2017-12-12 20:55:28.119162","timezone_type":3,"timezone":"UTC"}}, , 1, App\User, 2017-12-12 20:55:28, 2017-12-12 20:55:28))

As you can see it's the notifiable_type and notifiable_id doesn't make any sense since it's not in migration

sutherland's avatar
Level 28

You need to change $table->morphs('php '); in your notifications migration to $table->morphs('notifiable');

1 like

Please or to participate in this conversation.