I wan to add the sector id to the request but when I submit the data nothing store on it. Here is my code
public function store(QuestionRequest $request)
{
$data = $request->all();
Question::create($data);
$sectors = Sector::lists('id');
foreach($sectors as $sector){
CustomizeQuestion::create(array_add($request->all(), 'sector_id', $sector));
}
flash()->success('New question has been added.');
return redirect('questions');
}
I have tried this code also but it is the same :
public function store(QuestionRequest $request)
{
$data = $request->all();
Question::create($data);
$sectors = Sector::lists('id');
foreach($sectors as $sector){
$data['sector_id'] = $sector;
CustomizeQuestion::create($data);
}
flash()->success('New question has been added.');
return redirect('questions');
}
If you only want to add one 'id' to your request as you said, you can simply do this before creating anything :
$data = $request->all();
$data['sector_id'] = whatever you want;
Question::create($data);
Or like the second way you showed.
If this approach doesn't work verify if you have your properties specified in the model's fillable array and if you are using the correct property name as you specified in your migration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With