/** * Store a newly created resource in storage. * * @return Response */ public function store() { $input = Input::all(); $aturan = array('kelas' => 'required', 'sub' => 'required'); $pesan = array('kelas.required' => 'Kelas harus diisi', 'sub.required' => 'Sub Kelas harus diisi'); $validasi = Validator::make($input, $aturan, $pesan); if ($validasi->fails()) { return Redirect::back()->withInput()->withErrors($validasi); } else { //simpan $kode = Input::get('kelas') . "-" . Input::get('sub'); $cek = Kelas::where('kd_kelas', '=', $kode)->count(); if ($cek > 0) { return Redirect::back()->withInput()->with('pesan', "<div class='alert alert-danger'>Kode Kelas sudah digunakan</div>"); } else { $kelas = new Kelas(); $kelas->kd_kelas = $kode; $kelas->kelas = Input::get('kelas'); $kelas->subkelas = Input::get('sub'); $kelas->save(); return Redirect::to('admin/kelas')->with('pesan', "<hr><div class='alert alert-info'>Data Berhasil disimpan</div>"); } } }