Beispiel #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $input = Input::all();
     $validasi = Validator::make($input, Siswa::$rules, Siswa::$pesan);
     if ($validasi->fails()) {
         return Redirect::to('admin/siswa/create')->withInput()->withErrors($validasi);
     } else {
         $siswa = new Siswa();
         $siswa->nis = Input::get('nis');
         $siswa->nisn = Input::get('nisn');
         $siswa->nm_siswa = Input::get('nama');
         $siswa->jk = Input::get('jk');
         $siswa->tmp_lahir = Input::get('tempat');
         $siswa->tgl_lahir = date('Y-m-d', strtotime(Input::get('tanggal')));
         $siswa->agama = Input::get('agama');
         $siswa->nm_ayah = Input::get('ayah');
         $siswa->nm_ibu = Input::get('ibu');
         $siswa->alamat = Input::get('alamat');
         $siswa->thn_sttb = Input::get('tahun');
         $siswa->email = Input::get('email');
         if (Input::hasFile('foto')) {
             $file = Input::file('foto');
             $filename = str_random(5) . '-' . $file->getClientOriginalName();
             $destinationPath = 'uploads/siswa/';
             $file->move($destinationPath, $filename);
             $siswa->foto = $filename;
         }
         $siswa->save();
         //membuat siswa baru
         $siswa = Sentry::register(array('password' => Input::get('nis'), 'username' => Input::get('nis')), true);
         //cari group berdasarkan nama=siswa
         $siswaGroup = Sentry::findGroupByName('siswa');
         $siswa->addGroup($siswaGroup);
         $data = array('kd_rombel' => Input::get('tahun1') . '-' . Input::get('tahun2') . '-' . Input::get('kelas'), 'nis' => Input::get('nis'));
         DB::table('siswa_rombel')->insert($data);
         $riwayat = array('ke_rombel' => Input::get('tahun1') . '-' . Input::get('tahun2') . '-' . Input::get('kelas'), 'nis' => Input::get('nis'), 'tanggal' => Date('Y-m-d'), 'status' => 1);
         DB::table('riwayat_rombel')->insert($riwayat);
         return Redirect::to('admin/siswa')->with('pesan', "<hr><div class='alert alert-info'>\n\t\t\t\t\t\tData Berhasil disimpan</div>");
     }
 }