Ejemplo n.º 1
0
 public function addUserPost()
 {
     $profile = Profile::where('no_gaji', Request::get('no_gaji'))->first();
     if (!empty($profile)) {
         Session::flash('error', 'Gagal. No gaji *' . Request::get('no_gaji') . '* bertindih.');
         return Redirect::back()->withInput();
     }
     $no_anggota = Profile::where('no_anggota', Request::get('no_anggota'))->first();
     if (!empty($no_anggota)) {
         Session::flash('error', 'Gagal. No anggota *' . Request::get('no_anggota') . '* bertindih.');
         return Redirect::back()->withInput();
     }
     $nokp = Profile::where('nokp', Request::get('nokp'))->first();
     if (!empty($nokp)) {
         Session::flash('error', 'Gagal. No KP *' . Request::get('nokp') . '* telah wujud, dengan No Gaji *' . $nokp->no_gaji . '*.');
         return Redirect::back()->withInput();
     }
     $validation = Validator::make(Request::all(), ['no_anggota' => 'required|numeric', 'no_gaji' => 'required|numeric', 'profile_category_id' => 'required|numeric', 'nama' => 'required', 'nokp' => 'required', 'jantina_id' => 'required', 'bangsa' => 'required', 'jumlah_yuran_bulanan' => 'required|numeric', 'zon_gaji_id' => 'required|numeric']);
     if ($validation->fails()) {
         Session::flash('error', 'Sila isikan ruangan dengan format yang betul');
         return Redirect::back()->withInput()->withErrors($validation);
     }
     $profile = new Profile();
     $profile->fill(Request::all());
     $profile->jumlah_yuran_bulanan = Request::get('jumlah_yuran_bulanan');
     $profile->nama = strtoupper(Request::get('nama'));
     $profile->tarikh_ahli = Carbon::now();
     $profile->jantina_id = Request::get('jantina_id');
     $profile->alamat1 = strtoupper(Request::get('alamat1'));
     $profile->alamat2 = strtoupper(Request::get('alamat2'));
     $profile->jawatan = strtoupper(Request::get('jawatan'));
     $profile->email = strtoupper(Request::get('email'));
     $profile->taraf_jawatan = strtoupper(Request::get('taraf_jawatan'));
     if ($profile->save()) {
         Session::flash('success', 'Berjaya. Anggota baru telah didaftarkan');
     } else {
         Session::flash('error', 'Gagal. Anggota baru gagal didaftarkan');
     }
     return Redirect::route('members.profiles.addUser');
 }