Example #1
0
 /**
  * Creates a new Unit model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Unit();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     if (Session::get('level') == '1' || Session::get('level') == '2' && Session::get('fingerprint') == md5($_SERVER['HTTP_USER_AGENT'] . $_SERVER['REMOTE_ADDR'])) {
         $postData = Input::All();
         $messages = ['unit_name.required' => 'กรุณากรอก'];
         $rules = ['unit_name' => 'required'];
         $validator = Validator::make($postData, $rules, $messages);
         if ($validator->fails()) {
             return Redirect::route('unit.create')->withInput()->withErrors($validator);
         } else {
             $data = Request::all();
             $Unit = new Unit();
             $Unit->unit_name = $data['unit_name'];
             DB::transaction(function () use($Unit) {
                 $Unit->save();
             });
             Session::flash('savedata', save_data);
             return Redirect::to('unit');
         }
     } else {
         return Redirect::to('/');
     }
 }