i have admin_report table to store report option created by admin and report table to store data after user report any post. admin_report_id(checkbox option) is foreign key in report table.how to store the multiple value of selected checkbox in database as foreign key?
here is the error: its not passing the id of checkbox
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (
fyp
.report
, CONSTRAINTreport_admin_report_id_foreign
FOREIGN KEY (admin_report_id
) REFERENCESadmin_report
(id
) ON DELETE CASCADE ON UPDATE CASCADE) (SQL: insert intoreport
(report
,postqs_id
,admin_report_id
,user_id
,updated_at
,created_at
) values (ss, 18, 18, 5, 2018-01-12 11:34:30, 2018-01-12 11:34:30))
controller:
public function store(Request $request,Postqs $postqs,$id,Report $report, Admin_report $admin_report)
{
foreach ($report as $key => $report) {
$data = $request->all();
$data = $request->all();
$user = auth()->user();
$user->report()->create([
'report' => $data['report'],'postqs_id' => $id,'admin_report_id'=>$id
]);
}
blade:
@foreach ($admin_report as $key => $report)
<label class="container2">
<input type="checkbox" name="report[]">
</select>
<span class="checkmark"></span>
</label>
@endforeach
relationship :
public function report(){
return $this->hasMany('App\Report');
}
public function postqs(){
return $this->hasMany('App\Postqs','postqs_id','id');
}
Aucun commentaire:
Enregistrer un commentaire