/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Bancos();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Bancos'])) {
         $model->attributes = $_POST['Bancos'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Ejemplo n.º 2
0
 public function postNewBank()
 {
     $inp = Input::all();
     $rules = array('banco' => 'required', 'numCuenta' => 'required', 'tipoCuenta' => 'required', 'url' => 'required', 'img' => 'required|image|max:3000');
     $msg = array('required' => 'El campo es obligatorio', 'image' => 'El archivo debe ser una imagen', 'max' => 'El archivo no debe tener mas de 3Mb');
     $validator = Validator::make($inp, $rules, $msg);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $banco = new Bancos();
     $banco->banco = $inp['banco'];
     $banco->num_cuenta = $inp['numCuenta'];
     $banco->tipo = $inp['tipoCuenta'];
     $banco->tipo = $inp['tipoCuenta'];
     $banco->link = $inp['url'];
     $file = Input::file('img');
     if (file_exists('images/bancos/' . $file->getClientOriginalName())) {
         //guardamos la imagen en public/imgs con el nombre original
         $i = 0;
         //indice para el while
         //separamos el nombre de la img y la extensión
         $info = explode(".", $file->getClientOriginalName());
         //asignamos de nuevo el nombre de la imagen completo
         $miImg = $file->getClientOriginalName();
         //mientras el archivo exista iteramos y aumentamos i
         while (file_exists('images/bancos/' . $miImg)) {
             $i++;
             $miImg = $info[0] . "(" . $i . ")" . "." . $info[1];
         }
         //guardamos la imagen con otro nombre ej foto(1).jpg || foto(2).jpg etc
         $file->move("images/bancos/", $miImg);
         $blank = Image::make('images/b200.jpg');
         $img = Image::make('images/bancos/' . $miImg);
         if ($img->width() > $img->height()) {
             $img->widen(300);
         } else {
             $img->heighten(300);
         }
         if ($img->width() > 300) {
             $img->widen(300);
         }
         $blank->insert($img, 'center')->interlace()->save('images/bancos/' . $miImg);
         if ($miImg != $file->getClientOriginalName()) {
             $banco->imagen = $miImg;
         }
     } else {
         $file->move("images/bancos/", $file->getClientOriginalName());
         $blank = Image::make('images/b200.jpg');
         $img = Image::make('images/bancos/' . $file->getClientOriginalName());
         if ($img->width() > $img->height()) {
             $img->widen(300);
         } else {
             $img->heighten(300);
         }
         if ($img->width() > 300) {
             $img->widen(300);
         }
         $blank->insert($img, 'center')->interlace()->save('images/bancos/' . $file->getClientOriginalName());
         $banco->imagen = $file->getClientOriginalName();
     }
     if ($banco->save()) {
         Session::flash('success', 'Banco creado satisfactoriamente');
         return Redirect::to('administrador/editar-banco');
     } else {
         Session::flash('error', 'Error al crear el banco');
         return Redirect::back();
     }
 }