简体   繁体   中英

Multiple mysql row entries for no apparent reason (happens once in a while)

I have the following code for store() in my controller. Although the awkward delete was added later to get rid of the problem, it did not work.

public function store()
{
    $input = \Input::all();
    $userdetail = \Auth::User();

    foreach($input['user_id'] as $user_id) {
        \StudentAttendance::where('academicsession_id', '=', $input['academicsession_id'])
            ->where('class_id', '=', $input['class_id'])
            ->where('section_id', '=', $input['section_id'])
            ->where('attendance_on', '=', $input['attendance_on'])
            ->where('user_id', '=', $user_id)
            ->delete();
        $obj = new \StudentAttendance();
        $obj->academicsession_id = $input['academicsession_id'];
        $obj->class_id = $input['class_id'];
        $obj->section_id = $input['section_id'];
        $obj->user_id = $user_id;
        $obj->attendance_on = $input['attendance_on'];

        $obj->is_present = (isset($input['is_present'][$user_id])) ? 1 : 0;
        $obj->addBy = $userdetail['id'];
        $obj->status_id = 1;
        $obj->save();
    }

    return \Redirect::to('teachers/attendance')->with('status_success', trans('msg.success_attendance_saved'));
}

The problem is, every once in a while, for no apparent reason, I get duplicate entries in my db with same created_at and updated_at timestamps.

Please follow the link to see the screenshot ( http://i.imgur.com/WGciSVW.jpg?1 )

Not really sure what might be causing it to happen. Any help is appreciated. Thanks

单击后禁用/隐藏提交按钮可能是由于频繁单击导致此错误。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM