/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { $album_name = Input::get('name'); $album_slug = str_replace(" ", "-", strtolower($album_name)); Album::create(['name' => $album_name, 'slug' => $album_slug]); return redirect('/'); }
public function postCreate() { $rules = array('name' => 'required', 'cover_image' => 'required|image'); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::route('create_album_form')->withErrors($validator)->withInput(); } // end if $file = Input::file('cover_image'); $random_name = str_random(8); $destinationPath = 'albums/'; $extension = $file->getClientOriginalExtension(); $filename = $random_name . "." . $extension; $uploadSuccess = Input::file('cover_image')->move($destinationPath, $filename); $album = Album::create(array('name' => Input::get('name'), 'description' => Input::get('description'), 'cover_image' => $filename, 'user_id' => \Sentry::getUser()->id)); /* $filename = Input::file('cover_image'); $random_name = str_random(8); $destinationPath = 'albums/'; $extension = $filename->getClientOriginalExtension(); $uploadSuccess = Input::file('cover_image')->move($destinationPath, $filename . "." . $extension); $album = Album::create(array( 'name' => Input::get('name'), 'description' => Input::get('description'), 'cover_image' => $filename . "." . $extension, )); */ return Redirect::route('show_album', array('id' => $album->id)); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store() { // $input = Request::all(); $img_dir = "uploads/album/"; $img_thumb_dir = $img_dir . "/thumbs/"; // create an image manager instance with favored driver //$manager = new ImageManager(array('driver' => 'imagick')); // Create folders if they don't exist if (!file_exists($img_dir)) { mkdir($img_dir, 0777, true); } // Create Thumbnail folders if they don't exist if (!file_exists($img_thumb_dir)) { mkdir($img_thumb_dir, 0777, true); } if (Request::hasFile('photo')) { $img = Request::file('photo'); $filename = md5(microtime() . $img->getClientOriginalName()) . "." . $img->getClientOriginalExtension(); $upload_success = $img->move($img_dir, $filename); // resizing an uploaded file Image::make($img_dir . $filename)->resize(200, 200)->save($img_thumb_dir . $filename); $input['image_name'] = $filename; $input['url'] = $img_dir . $filename; $input['thumb_url'] = $img_thumb_dir . $filename; } $user = Album::create($input); return redirect('/album/list/')->with('status', "Album Created Successfully"); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(UploadImageRequest $request, $user) { if (!file_exists(public_path() . '/upload')) { mkdir(public_path() . '/upload'); } if (!file_exists(public_path() . '/upload/images/')) { mkdir(public_path() . '/upload/images'); } $id = Auth::user()->id; $auth = substr(md5(Auth::user()->id . Auth::user()->email), 0, 10); $resource = $request->except(['_token', 'image']); //dd($request->file('image')); if (!$request->get('album_id')) { $data_album = ['album_name' => 'Untitled', 'album_title' => 'Untitled album', 'user_id' => $id]; if (!($album = Album::create($data_album))) { return redirect()->route('photo.create', $user)->withErrors('Unexpected error!'); } $resource['album_id'] = $album->id; } if ($request->hasFile('image')) { $file = $request->file('image'); $imageName = date('d-m-Y_h-i-s') . '_' . $id . '_' . $file->getClientOriginalName(); $path = $this->path . '/' . $id . '_' . $auth; $destination = $path; $folder = public_path() . '/' . $path; if (!file_exists($folder)) { mkdir($folder); } $image = ['image_name' => $imageName, 'image_size' => $file->getSize(), 'user_id' => $id, 'fullsize_url' => $path . '/' . $imageName]; if ($file->move($destination, $imageName) && Image::create(array_merge($resource, $image))) { return response()->json(['message' => 'Your photo has been upload!']); } } return response()->json(['message' => 'Unexpected errors']); }
public function save(Request $request) { $album = Album::create($request->input('Album', [])); if ($album->isInvalid()) { return redirect('/album/new')->withErrors($album->getErrors()); } return redirect('/albums')->with('success', 'Album created!'); }
public function run() { $albums = [['title' => 'Bruiloft 29/11', 'description' => '', 'seoble_type' => 'App\\Album', 'position' => [1, 2, 3, 4]], ['title' => 'Golf 22/10', 'description' => '', 'seoble_type' => 'App\\Album', 'position' => [1, 2, 3, 4]], ['title' => '', 'description' => '', 'seoble_type' => 'App\\Album', 'position' => [1, 2, 3, 4]], ['title' => '', 'description' => '', 'seoble_type' => 'App\\Album', 'position' => [1, 2, 3, 4]]]; foreach ($albums as $album) { $a = Album::create(['position' => json_encode($album['position'])]); Seo::create(['title' => $album['title'], 'slug' => str_slug($album['title']), 'description' => $album['description'], 'seoble_type' => "App\\Album", 'seoble_id' => $a->id]); } }
public function run() { $users = [["id" => 1, "username" => "Torch", "first_name" => "Ján", "last_name" => "Krnáč", "password" => Hash::make('123456'), "admin" => 1, "email" => "*****@*****.**"]]; $albums = [["id" => 1, "name" => "from posts", "albumable_id" => 1, "albumable_type" => "App\\User", "hash" => "abcde"]]; if (!User::find(1)) { foreach ($users as $user) { User::create($user); } foreach ($albums as $album) { Album::create($album); } } }
public function changeCoverPhoto($user, UpdateCoverPhotoRequest $request) { if ($request->hasFile('image')) { $file = $request->file('image'); $album = Album::where(['album_name' => 'Cover photos', 'user_id' => $this->user->id])->get()->first(); if (count($album)) { $albumId = $album->id; } else { if ($newAlbum = Album::create(['album_name' => 'Cover photos', 'album_title' => 'Cover photos', 'album_description' => '', 'user_id' => $this->user->id])) { $albumId = $newAlbum->id; } else { return response('Unexpected error!', 422); } } $destination = public_path() . '/upload/images/' . $this->user->id . '_' . $this->folder . '/cover'; if (!file_exists(public_path() . '/upload/images/' . $this->user->id . '_' . $this->folder)) { mkdir(public_path() . '/upload/images/' . $this->user->id . '_' . $this->folder); } if (!file_exists($destination)) { mkdir($destination); } $imageName = date('d-m-Y_h-i-s') . '_' . $this->user->id . '_' . $file->getClientOriginalName(); $imageUrl = 'upload/images/' . $this->user->id . '_' . $this->folder . '/cover/' . $imageName; $imageArr = ['image_name' => $imageName, 'fullsize_url' => $imageUrl, 'image_size' => $file->getSize(), 'image_caption' => '', 'user_id' => $this->user->id, 'album_id' => $albumId, 'make_as_cover_photo' => 1]; $changeImage = Image::find($this->hasCoverPhoto($this->user->id)); if (!is_null($changeImage)) { $changeImage->make_as_cover_photo = 0; $changeImage->save(); } if ($file->move($destination, $imageName) && Image::create($imageArr)) { $data['errors'] = 0; $data['msg'] = 'Your cover photo has been change!'; $data['imageUrl'] = url($imageUrl); return json_encode($data); } return response('Unexpected error while changging your cover photo!', 422); } }
public static function edit($action, array $data, $id) { $goods = self::find($id); if ($action == 'edit') { $rows = Album::where('pid', $id)->get(); $srcNum = Album::where('pid', $id)->count(); $path = 'uploads'; $files = Upload::fileUpload($path); $uploadNum = count($files); if ($uploadNum < $srcNum) { $i = 0; foreach ($files as $file) { $array = ['album_path' => $file['name']]; unlink("uploads/" . $rows[$i]->album_path); $rows[$i]->update($array); $i++; } for ($j = $i; $j < $srcNum; $j++) { $rows[$j]->delete(); unlink("uploads/" . $rows[$j]->album_path); } } elseif ($uploadNum == $srcNum) { $i = 0; foreach ($files as $file) { $updateArr = ['album_path' => $file['name']]; unlink("uploads/" . $rows[$i]->album_path); $rows[$i]->update($updateArr); $i++; } } elseif ($uploadNum > $srcNum) { $i = 0; foreach ($rows as $row) { $updateArr = array('album_path' => $files[$i]['name']); unlink("uploads/" . $row->album_path); $row->update($updateArr); $i++; } for ($j = $i; $j < $uploadNum; $j++) { $insertArr = array('pid' => $id, 'album_path' => $files[$j]['name']); Album::create($insertArr); } } if ($goods->update($data)) { return self::success(['pro_id' => $id]); } return self::fail(); } elseif ($action == 'delete') { if (self::where('id', $id)->delete()) { foreach (Album::where('pid', $id)->get() as $row) { unlink("uploads/" . $row->album_path); } Album::where('pid', $id)->delete(); Comments::where('pro_id', $id)->delete(); return self::success(); } return self::fail(); } }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(CreateAlbumRequest $request, $user) { $resource['user_id'] = $user; return Album::create(array_merge($request->except(['_token']), $resource)) ? response()->json(['message' => 'Your album created!']) : response()->json(['message' => 'Error!!']); }