Answer the question
In order to leave comments, you need to log in
How to write array value to laravel base?
$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
Answer the question
In order to leave comments, you need to log in
This is how it works, though I don’t know if there is a laravel method that allows you to do this in one line
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');
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question