简体   繁体   English

没有明显原因的多个mysql行条目(偶尔发生一次)

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

I have the following code for store() in my controller. 我的控制器中有以下用于store()的代码。 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. 问题是,每隔一段时间,没有明显的原因,我在数据库中得到重复的条目,它们具有相同的created_at和updated_at时间戳。

Please follow the link to see the screenshot ( http://i.imgur.com/WGciSVW.jpg?1 ) 请点击链接查看屏幕截图( http://i.imgur.com/WGciSVW.jpg?1

Not really sure what might be causing it to happen. 不太确定可能是什么导致了这种情况的发生。 Any help is appreciated. 任何帮助表示赞赏。 Thanks 谢谢

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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