/** * Creates a new Absensi model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Absensi(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
public function afterSave($insert, $changedAttributes) { $absensi = Absensi::deleteAll(['id_peserta' => $this->id]); foreach ($this->events as $id_event) { $absensi = new Absensi(); $absensi->id_peserta = $this->id; $absensi->id_event = $id_event; $absensi->kehadiran = 0; $absensi->save(); } }
/** * Store a newly created resource in storage. * * @return Response */ public function store(AbsensiRequest $request) { // $input = $request->except('_token', 'jurusan', 'tanggal', 'bulan', 'tahun'); $jurusan = $request->get('jurusan'); Absensi::where('tanggal', '=', $request->get('tanggal'))->where('bulan', '=', $request->get('bulan'))->where('tahun', '=', $request->get('tahun'))->where('id_jurusan', '=', $jurusan)->delete(); foreach ($input as $key => $val) { $implode = explode('-', $key); $mahasiswa = $implode[1]; $absensi = new Absensi(); $absensi->id_mahasiswa = $mahasiswa; $absensi->id_jurusan = $jurusan; $absensi->tanggal = $request->get("tanggal"); $absensi->bulan = $request->get('bulan'); $absensi->tahun = $request->get('tahun'); $absensi->absen = $input[$key]['absen']; $absensi->save(); } if ($this->auth->user()->status == 'admin') { return redirect(route('admin.absensi.index')); } return redirect(route('guru.absensi.index')); }