$request->except('_token');
public function store(ApplicantSkillsRequest $request)
{
$applicant = $request->user();
$params = $request->except('_token');
ApplicantSkill::create([
'user_id' => $applicant->id,
'name' => $params['name'],
'level' => $params['level'],
]);
return redirect()->route('applicant.skills.index');
}
public function skills()
{
return $this->hasMany(ApplicantSkills::class);
}
user_id name level
1 js 55
1 php 85
public function store(ApplicantSkillsRequest $request)
{
$applicant = $request->user();
$params = $request->except('_token');
$levels = $request->level;
foreach($request->name as $i => $name) {
$skill = new ApplicantSkill;
$skill->user_id = $applicant->id;
$skill->name = $name;
$skill->level = $levels[$i];
$skill->save();
}
return redirect()->route('applicant.skills.index');
}
$request = [
'name' => ['js', 'php'],
'level' => ['55', '85'],
];
$collection = collect($request['name'])->map(function ($item, $key) use ($request) {
return ['name' => $item, 'level' => $request['level'][$key]];
});
ApplicantSkill::create($collection)