douying0108 2016-09-26 13:56
浏览 52
已采纳

Laravel - 没有在表格中写新内容

I have added a new column to a table in my DB with migration. The column was created correctly. But when I am trying to write values to it, nothing gets written. This is my code:

if ($alternativeId > 0) {
            $answered = 'yes';
        }
        else {
            $answered = 'not';    
        }

        $answer = Answer::create([
            'question_id' => $questionId,
            'player_id' => $player->id,
            'quiz_id' => $quiz->id,
            'score' => $score,
            'answered' => $answered
        ]);

The variable $answered gets a value, I have tested that in the console, when I was testing it with:

return ['answered' => $answered]

And I was getting the correct values there, but nothing was written in the DB. Not sure why is that happening?

  • 写回答

1条回答 默认 最新

  • doukangbin9698 2016-09-26 13:58
    关注

    You need to add answered in the $fillable array, because create method uses mass assignment.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 CSS实现渐隐虚线框
  • ¥15 有没有帮写代码做实验仿真的
  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真