Customize Messages Table
Lukada-taiya opened this issue · 1 comments
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.
In your app code, are you referencing your new model as well?
//Method
\App\Models\Message::create([
'thread_id' => $thread->id,
'user_id' => Auth::id(),
'type' => 'file',
'body' => $filename,
]);
It seems like you're still referencing the package's original model