public function store(Request $request) { $this->validate($request, ['nickname' => 'required|unique:leaves|max:255', 'content' => 'required']); $leave = new Leave(); $leave->nickname = Input::get('name'); $leave->content = Input::get('comment'); if ($leave->save()) { return Redirect::to('home'); } else { return Redirect::back()->withInput()->withErrors('保存失败!'); } }
public function postAdd() { $mulai = Input::get('start'); $selesai = Input::get('finish'); //pecah tanggal mulai $pecah_mulai = explode('/', $mulai); $hari_mulai = $pecah_mulai[1]; $bulan_mulai = $pecah_mulai[0]; $tahun_mulai = $pecah_mulai[2]; //pecah tanggal selesai $pecah_selesai = explode('/', $selesai); $hari_selesai = $pecah_selesai[1]; $bulan_selesai = $pecah_selesai[0]; $tahun_selesai = $pecah_selesai[2]; $cuti_mulai = gregoriantojd($bulan_mulai, $hari_mulai, $tahun_mulai); $cuti_selesai = gregoriantojd($bulan_selesai, $hari_selesai, $tahun_selesai); $selisi = $cuti_selesai - $cuti_mulai + 1; $libur = 0; for ($x = 1; $x <= $selisi; $x++) { $hitung_waktu = mktime(0, 0, 0, $bulan_mulai, $hari_mulai + $x, $tahun_mulai); if (date('w', $hitung_waktu) == 0 || date('w', $hitung_waktu) == 6) { $libur++; } } $jumlah_curi = $selisi - $libur; $cuti = Request::all(); $cuti['period'] = $jumlah_curi; $query = Leave::create($cuti); $query == true ? $message = 'Berhasil tambah data' : ($message = 'Gagal tambah data'); return redirect('leave')->with('message', $message); }
public function destroy($id) { $leave = Leave::FindOrFail($id); $leave->delete(); session()->flash('flash_message', 'Je hebt de aanvraag verwijderd.'); return redirect('leaves'); }
public function approve($leave) { $leave = Leave::find($leave); $balance = $leave->teammate->earned - $leave->teammate->availed - 1; if ($balance < 0) { return redirect()->back()->with('error', 'Sorry, ' . $leave->teammate->full_name . ' has already availed his earned leaves!'); } $leave->update(['approved' => 1]); //send email Mail::send('emails.leave-approved', ['leave' => $leave], function ($m) use($leave) { $m->to($leave->teammate->email, $leave->teammate->name)->subject('Leave has been approved'); }); return redirect()->route('home')->with('status', 'Leave has been approved!'); }