I'm new to Laravel and would I'm confused on how to properly store a data from a form with a polymorphic relation. I have three models.
Salary Grade Model
public function salaryallowance() {
return $this->morphOne('App\SalaryAllowanceModel', 'salary');
}
Salary Matrix Model
public function salaryallowance() {
return $this->morphOne('App\SalaryAllowanceModel', 'salary');
}
Salary Allowance Model
public function salary() {
return $this->morphTo();
}
Salary Allowance Controller
public function store(Request $request) {
SalaryAllowanceModel::create ([
'salary_id' => $request->position,
'salary_type' => get_class($request),
'salary_allowance' => $request->allowance,
'salary_transportation' => $request->transportation,
'salary_medical' => $request->medical,
'salary_education' => $request->education,
'salary_housing' => $request->housing,
'salary_clothing' => $request->clothing
]);
return back();
}
I'm having a hard time to do a syntax for storing the data.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire