Ejemplo n.º 1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Facility();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Facility'])) {
         $model->attributes = $_POST['Facility'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->num));
         }
     }
     $this->render('create', array('model' => $model));
 }
Ejemplo n.º 2
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     //Validation
     $rules = array('name' => 'required|unique:facilities,name');
     $validator = Validator::make(Input::all(), $rules);
     if ($validator->fails()) {
         return Redirect::route('facility.index')->withErrors($validator)->withInput();
     } else {
         // Add
         $facility = new Facility();
         $facility->name = Input::get('name');
         // redirect
         try {
             $facility->save();
             $url = Session::get('SOURCE_URL');
             return Redirect::to($url)->with('message', trans('messages.successfully-updated-facility'))->with('activefacility', $facility->id);
         } catch (QueryException $e) {
             Log::error($e);
         }
     }
 }