我正在创建一个调查应用程序,基本上当用户选择“选择”的输入类型时,它会出现一个可以动态增加的选项输入,但是我在我的数据库中插入这些选项时遇到了一些问题,我使用同步方法来在我的表中插入这些选项,但给我一个错误
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'toufarto.question_id' doesn't exist (SQL: select `option_question_id` from `question_id` where `id` = 11)
这是我的代码:
Tables:
questions:
- id;
- input_type;
option_question
- id;
- label_option;
- question_id
我的控制器:
public function store(Request $request)
{
$this->validate($request, array(
'label_option' => 'max:255',
'input_type' => 'required|integer'
));
$question = new Question();
$question->input_type = $request->input_type;
$question->save();
$question->options()->sync($request->option, false);
Session::flash('success', 'success');
return back();
}
我的问题模型:
public function options()
{
return $this->belongsToMany(OptionQuestion::class,'question_id','id');
}
我的选项问题模型:
class OptionQuestion extends Model
{
protected $table = "option_question";
}
注意:我如何将标签列添加到“同步”方法,因为我需要从表单的选项字段中插入标签