I am having a hard with this one since it is my first time doing this. What I'm trying to do is to add data inside a single column using multiple input fields, but every time I save the data, the columns are blank, what is the correct way to do it? I'll provide the codes and snippets below.
Controller.php file
$user = new ApplicantEducModel();
$user->app_id = $app_id;
$user->schoolname = Str::upper($request->input(
[
'elemSchoolName',
'secondarySchoolName',
'tertiarySchoolName',
]));
$user->inclusive_year = $request->input(
[
'elemSchoolYear',
'secondarySchoolYear',
'tertiarySchoolYear',
]);
$user->school_address = Str::upper($request->input(
[
'elemAdd',
'secondaryAdd',
'tertiaryAdd',
]
));
CodePudding user response:
You can do bulk insertation like:
$user = ApplicantEducModel::insert([
[
'app_id' => $app_id,
'schoolname' => Str::upper($request->elemSchoolName),
'inclusive_year' => $request->elemSchoolYear,
'school_address' => Str::upper($request->elemAdd)
],
[
'app_id' => $app_id,
'schoolname' => Str::upper($request->secondarySchoolName),
'inclusive_year' => $request->secondarySchoolYear,
'school_address' => Str::upper($request->secondaryAdd)
],
[
'app_id' => $app_id,
'schoolname' => Str::upper($request->tertiarySchoolName),
'inclusive_year' => $request->tertiarySchoolYear,
'school_address' => Str::upper($request->tertiaryAdd)
]
]);
But first of all make sure these fields are set as fillable
in ApplicantEducModel
model. To do that just add below code to your model class:
protected $fillable = [
'app_id',
'schoolname',
'inclusive_year',
'school_address'
];