public static function find_user_request_type($event_id, $user_id) { $count_request_event = request_job::where('event_id', '=', $event_id)->where('user_id', '=', $user_id)->count(); $event = event::where("id", "=", $event_id)->first(); $event_date = $event->event_date; $count_request_day = request_job::where("start_date", "<=", $event_date)->where("end_date", ">=", $event_date)->where("event_id", "=", "0")->where('user_id', '=', $user_id)->count(); if ($count_request_event > 0) { return "request_event_user"; } else { if ($count_request_day > 0) { return "request_job_user"; } else { return "all_user"; } } }
public static function request_event() { $count_job_request = request_job::where('event_id', '=', Request::input('event_id'))->where('user_id', '=', Auth::user()->id)->count(); if ($count_job_request > 0) { return redirect::to("event")->with('status', "คุณได้ยื่นขอทำงานนี้แล้ว"); } else { $event = event::where("id", "=", Request::input('event_id'))->first(); $request_name = $event->event_name; $start_date = $event->event_date; $end_date = $event->event_date; $duration = $event->meeting_period; //===================================================================================== $request = new request_job(); $request->request_name = $request_name; $request->user_id = Auth::user()->id; $request->start_date = $start_date; $request->end_date = $end_date; $request->duration = $duration; $request->event_id = Request::input('event_id'); $request->multiple_day = 0; $url = "event"; if ($request->save()) { return redirect::to($url)->with('status', "ยื่นขอทำงานสำเร็จ"); } else { return redirect::to($url)->withInput(Request::except('password'))->withErrors("เกิดข้อผิดพลาด - ไม่สามารถยื่นขอทำงานนี้ได้ กรุณาติดต่อผู้ดูแลระบบ"); } } }