I have 7 input fields. However the user may only pick a maximum of 3 subjects. How would I be able to update these inputs into my table?
public function searchgrouppost(){
$subject1 = Input::get('subject1');
$subject2 = Input::get('subject2');
$subject3 = Input::get('subject3');
$subject4 = Input::get('subject4');
$subject5 = Input::get('subject5');
$subject6 = Input::get('subject6');
$subject7 = Input::get('subject7');
My aim is to end up with something like this:
DB::table('mytable')->where('id', 6)
->update(['subject' => $firstchosensubject,
'subjecttwo' => $secondchosensubject,
'subjectthree' =>$thirdchosensubject]);
So far I have:
$subjects = [];
$inputs = Input::all();
array_walk($inputs, function ($v, $k) use (&$subjects) {
if(starts_with($k, 'subject')) {
$subjects[$k] = $v;
}
});
$index = count($subjects);
Shown above I have all inputs in this $subjects
variable. How do I extract these values for table input?