public function store() { $data = Input::all(); $data['is_single'] = 0; $post = new Post(); $post->save(); $data['post_id'] = $post->id; $album = AlbumsHelper::save($data); $filesStatus = Input::get('file_status'); $upload_folder = "upload/albums/" . uniqid(date('ymdHisu')); $files = Input::file('path'); $captions = Input::get('caption'); $status = 'success'; foreach ($files as $index => $file) { if ($file->isValid() && $filesStatus[$index] != 0) { $image = new Image(); $name = $file->getFilename() . uniqid() . "." . $file->getClientOriginalExtension(); $file->move(public_path() . "/" . $upload_folder, $name); $post = new Post(); $post->save(); $image->path = $upload_folder . "/" . $name; $image->caption = $captions[$index]; $image->album_id = $album->id; $image->count_like = 0; $image->post_id = $post->id; $status = $image->save(); if ($status == FALSE) { $status = 'fail'; break; } } } Session::flash('status', $status); return Redirect::to('album/create'); }
private function saveAlbum($index, $post) { $categories = Input::get('category'); $publices = Input::get('public'); $titles = Input::get('title'); $files = Input::file('path'); $file = $files[$index]; if ($file->isValid()) { $data['category_id'] = $categories[$index]; $data['user_id'] = Session::get('current_user'); $data['public'] = $publices[$index]; $data['title'] = $titles[$index]; $data['description'] = ""; $data['is_single'] = 1; $data['post_id'] = $post->id; return AlbumsHelper::save($data); } return false; }