/** * Store a newly created resource in storage. * * @return Response */ public function store(Request $request) { $nuevo = new Color(); // Preparamos un registro vacio para la tabla Local $nuevo->nombre_color = $request->get('nombre_color'); $nuevo->save(); return \Response::json(array('datos' => Color::all())); }
/** * Creates a new Color model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Color(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['index']); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Color model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Color(); $model->beforeSave(true); 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. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $validator = Validator::make($request->all(), ['name' => 'required|max:255', 'image' => "required|mimes:jpeg,bmp,png"]); if ($validator->fails()) { return redirect("admin/{$this->key}/create")->withErrors($validator)->withInput($request->all()); } $item = new Color(); $item->name = $request->name; $image = $request->image; $filename = time() . '.' . $image->getClientOriginalExtension(); //Имя файла $path = 'img/color/' . $filename; //Путь файла Image::make($image->getRealPath())->save($path); $item->image = $path; $item->save(); return redirect("admin/{$this->key}"); }