/** * Creates a new Gallery model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Gallery(); 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(Gallery $gallery, Requests\GalleryRequest $request) { $hash = Session::get('gallery_hash'); $gallery->fill($request->input()); $gallery->attachment_hash = $hash; $gallery->save(); Session::forget('gallery_hash'); $attachments = GalleryAttachment::where('hash', $hash)->get(); foreach ($attachments as $attachment) { $attachment->update(['comment' => \Input::get($attachment->id), 'link' => \Input::get('link' . $attachment->id)]); } \Session::flash('message', 'Галлерея создана'); return redirect()->route('admin.gallery.index'); }
public function upload($id) { if ($this->validate()) { $it = 0; foreach ($this->imageFiles as $file) { $path = 'uploads/' . $id . 'n' . $it . '.' . $file->extension; $file->saveAs($path); $gallery = new Gallery(); $gallery->id_tour = $id; $gallery->path = $path; $gallery->save(false); ++$it; } $img = Tour::findOne(['id' => $id]); $img->image = 'uploads/' . $id . 'n0' . '.' . $this->imageFiles[0]->extension; $img->save(false); return true; } else { return false; } }