I am doing this query
$disposes = Disposecollect::create([
'bag_id' => $request->input('bag_id'),
'station_id' => $station->id,
'undisposed_weight' => $weight->weight,
'disposed_weight' => $weight->weight - $weight->weight,
'status' => $request->input('status'),
'campus_id' => Auth::user()->campus_id
]);
And it suddenly it produce an error:
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (
ecoteneo
.disposecollects
, CONSTRAINTdisposecollects_campus_id_foreign
FOREIGN KEY (campus_id
) REFERENCEScampuses
(id
) ON DELETE CASCADE ON UPDATE CASCADE) (SQL: insert intodisposecollects
(bag_id
,station_id
,undisposed_weight
,disposed_weight
,status
,updated_at
,created_at
) values (6, 1, 5, 0, Undisposed, 2018-09-25 10:02:23, 2018-09-25 10:02:23))
The value of campus id from the user didn't pass in an insert query...
Is it my code in the part of:
'campus_id' => Auth::user()->campus_id
is this correct?