I tried to update into my database by using save(). As my primary key is an auto increment id, it creates a new row when I tried to use save().
I tried to use save($game_id, $newData) for testing and I got error message.
Below is my code :
Table add_game
id | game_id | user_id | ign | acc_id
1 | 3 | 1 | ignA | accA
2 | 3 | 1 | ignB | accB
3 | 3 | 1 | ignC | accC
Model
protected $table = 'add_game';
protected $allowedFields = [
'user_id',
'game_id',
'ign',
'acc_id'
];
Controller
$newData = [
'user_id' => session()->get('user_id'),
'game_id' => $game_id,
'ign' => $this->request->getVar('ign'),
'acc_id' => $this->request->getVar('acc_id')
];
$model->save($newData); // currently it keeps creating new record
$model->save($newData); // return me error message
How do I update my existing records? I want to update them base on my user_id as well as game_id. Thanks in advance guys!