public function store(Request $request) { //dd('jajaja'); $file = $request->file('file'); //obtenemos el campo file obtenido por el formulario $nombre = $file->getClientOriginalName(); //indicamos que queremos guardar un nuevo archivo en el disco local \Storage::disk('local')->put($nombre, \File::get($file)); \Excel::load('/storage/public/files/' . $nombre, function ($archivo) use(&$falla) { $result = $archivo->get(); //leer todas las filas del archivo foreach ($result as $key => $value) { $var = new Periodo(); $datos = ['bloque' => $value->bloque, 'inicio' => $value->inicio, 'fin' => $value->fin]; $validator = Validator::make($datos, Periodo::storeRules()); if ($validator->fails()) { Session::flash('message', 'Los Periodos ya existen o el archivo ingresado no es valido'); $falla = true; } else { $var->fill($datos); $var->save(); } } })->get(); if ($falla) { // Fallo la validacion de algun campus, retornar al index con mensaje return redirect()->route('Administrador.periodos.index'); } \Storage::delete($nombre); Session::flash('message', 'Los Periodos fueron agregados exitosamente!'); return redirect()->route('Administrador.periodos.index'); }
/** * Creates a new Periodo model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Periodo(); if ($model->load(Yii::$app->request->post()) && $model->save()) { $model->dtInicio = Yii::$app->formatter->asDate($model->dtInicio, 'php:Y-m-d'); //$model->dtInicio = DateTime::createFromFormat('Y/m/d', $model->dtInicio); //$model->dtInicio = date('d/m/Y', strtotime($model->dtInicio)); $model->dtTermino = Yii::$app->formatter->asDate($model->dtTermino, 'php:Y-m-d'); //Altera o formato para o formato do Mysql... //$model->dtInicio = date('Y-m-d', strtotime(Yii::$app->request->post('Periodo[dtInicio]') ) ); //$model->dtTermino = date('Y-m-d', strtotime(Yii::$app->request->post('Periodo[dtTermino]') ) ); $model->save(); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
public function postStore($year_id) { $user = User::fromToken(); $periodo = new Periodo(); $periodo->numero = Request::input('numero'); $periodo->fecha_inicio = Request::input('fecha_inicio'); $periodo->fecha_fin = Request::input('fecha_fin'); $periodo->actual = false; $periodo->year_id = $year_id; $periodo->fecha_plazo = Request::input('fecha_plazo'); $periodo->save(); return $periodo; }