Skip to content

Customize Messages Table #397

@maestro-00

Description

@maestro-00

Discussed in #396

Originally posted by Lukada-taiya September 14, 2023
I added a column called 'type' to the messages table to better cater for my needs.
I then went to messenger.php in the config directory and changed and changed this line,
'message_model' => Cmgmyr\Messenger\Models\Message::class,
to
'message_model' => \App\Models\Message::class,

The new Message model is a copy of the old one but with a change in this line,
//protected $fillable = ['thread_id', 'user_id', 'body'];
protected $fillable = ['thread_id', 'user_id', 'body', 'type'];

After these changes, I still get this error when I try to create a record in the database using the Message::create method

//Method
Message::create([
                'thread_id' => $thread->id,
                'user_id' => Auth::id(),
                'type' => 'file',
                'body' => $filename,
  ]);
//Error
SQLSTATE[HY000]: General error: 1364 Field 'type' doesn't have a default value
insert into `messages` (`thread_id`, `user_id`, `body`, `updated_at`, `created_at`) values (22, 3, 2023-09-14 02:13:00HOW-TO-USE.pdf, 2023-09-14 02:13:02, 2023-09-14 02:13:02)

What am I missing? Laravel isn't recognising the additional column in spite of adding the column in the fillable property.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions