Пример #1
0
 /**
  * Show the form for creating a new resource.
  * GET /ob/create
  *
  * @return Response
  */
 public function create()
 {
     $validate = LeaveOB::validate(Input::all());
     if ($validate->passes()) {
         if (Input::get('totalleaves') <= 0.0 or Input::get('totalleaves') === 'NaN') {
             $message = 'Please select correct date!';
             return Redirect::to('applyob')->with('error_message', $message);
         } else {
             $lastrow = LeaveOB::orderBy('created_at', 'desc')->first();
         }
         $data = new LeaveOB();
         $data->employee_id = Auth::user()->employee_id;
         if ($lastrow == null) {
             $data->leave_id = Str::random(8);
         } else {
             $data->leave_id = Str::random(8) . $lastrow->id;
         }
         $data->days_of_leave = Input::get('totalleaves');
         $data->wdays_of_leave = Input::get('totalleave');
         $data->date_from = Input::get('date_from');
         $data->time_from = Input::get('time_from');
         $data->date_to = Input::get('date_to');
         $data->time_to = Input::get('time_to');
         $data->company = Input::get('company');
         $data->address = Input::get('address');
         $data->reason = Input::get('reason');
         $data->save();
         return Redirect::to('applyob')->with('message', 'Your Application for Official Business (OB) is successfully send.Please Check Your Notification box to see if your leave  has  been approved.');
     } else {
         return Redirect::to('applyob')->withErrors($validate);
     }
 }