/** * Run the database seeds. * * @return void */ public function run() { if (rand(0, 1) == 1) { $url = "https://pixabay.com/api/?key=" . env('PIXABAY_API_KEY') . "&image_type=photo&category=buildings&safesearch=true&min_width=500"; $json = file_get_contents($url); $json_data = json_decode($json, true); $pixa_json = $json_data['hits']; foreach ($pixa_json as $image) { $pictureUploadResult = \Cloudinary\Uploader::upload($image['webformatURL']); if ($pictureUploadResult == null) { echo "Error uploading picture"; continue; } $picture = new Picture(); $picture->description = ""; $picture->url = $pictureUploadResult['secure_url']; $picture->cloudinary_public_id = $pictureUploadResult['public_id']; $picture->save(); $junction = new PropertyPictureBridge(); $all_properties = Property::all(); $one_property = $all_properties[rand(0, count($all_properties) - 1)]; $junction->property_id = $one_property->id; $junction->picture_id = $picture->id; $junction->save(); } } else { $api_key = env('FLICKR_API_KEY'); $query = 'new york city apartment'; $url = "https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=" . $api_key . "&tags=" . urlencode($query) . "&safe_search=1&per_page=20&format=json"; $json_data = file_get_contents($url); $json_data = substr($json_data, 14); $json_data = substr($json_data, 0, strlen($json_data) - 1); $json_data = json_decode($json_data, true); foreach ($json_data['photos']['photo'] as $photo) { $farm = $photo['farm']; $server = $photo['server']; $src = 'http://farm' . $farm . '.static.flickr.com/' . $server . '/' . $photo['id'] . '_' . $photo['secret'] . '_z.jpg'; $pictureUploadResult = \Cloudinary\Uploader::upload($src); if ($pictureUploadResult == null) { echo "Error uploading picture"; continue; } $picture = new Picture(); $picture->description = ""; $picture->url = $pictureUploadResult['secure_url']; $picture->cloudinary_public_id = $pictureUploadResult['public_id']; $picture->save(); $junction = new PropertyPictureBridge(); $all_properties = Property::all(); $one_property = $all_properties[rand(0, count($all_properties) - 1)]; $junction->property_id = $one_property->id; $junction->picture_id = $picture->id; $junction->save(); } } }
public function postIndex(UploadRequest $request) { $orginal = $request->file('picture'); $picture = new Picture(); $picture->save(); $tempname = uniqid('sotm-') . '.' . $orginal->getClientOriginalExtension(); $orginal->move('/tmp', $tempname); $picture->init("/tmp/{$tempname}"); $picture->addLocation($request); unlink("/tmp/{$tempname}"); }
/** * Run the database seeds. * * @return void */ public function run() { // Suppression préalable des fichiers de upload par l'utilisation de la variable storage définie à l'aide de l'instruction public_path('upload') du fichier de configuration config\filesystem.php) $files = Storage::allFiles(); //retroune un tableau des images de storage foreach ($files as $file) { Storage::delete($file); } //Supprimer toutes les lignes de la talble Pictures // DB::table('pictures')-> // Récupération d'un faker opétationnel // $faker = Faker\Factory::create(); $products = Product::all(); foreach ($products as $product) { // Stokage de l'image et récupération de l'uri $uri = str_random(15) . '_370x235.jpg'; Storage::put($uri, file_get_contents('http://lorempixel.com/people/370/325/')); Picture::create(['product_id' => $product->id, 'uri' => $uri, 'title' => $this->faker->name]); } // DB::table('pictures')->insert( // [ // [ // 'product_id' => '2' , // 'uri' => $uri // ], // ] // ); }
public function update(Request $request, $id) { $this->validate($request, ['name' => 'required|string', 'abstract' => 'required|max:255', 'content' => 'max:255', 'price' => 'required|numeric', 'quantity' => 'numeric', 'published_at' => 'in:true', 'status' => 'in:opened,closed', 'thumbnail' => 'image|max:5000']); $product = Product::find($id); if (!empty($request->input('tags'))) { $product->tags()->sync($request->input('tags')); } else { $product->tags()->detach(); } if ($request->input('delete') == 'true') { if (!is_null($product->picture)) { Storage::disk('local')->delete($product->picture->uri); $product->picture->delete(); } } if (!is_null($request->file('thumbnail'))) { $im = $request->file('thumbnail'); $ext = $im->getClientOriginalExtension(); $uri = str_random(12) . '.' . $ext; $im->move(env('UPLOAD_PATH', './uploads'), $uri); Picture::create(['uri' => $uri, 'type' => $ext, 'size' => $im->getClientSize(), 'product_id' => $product->id, 'title' => $product->name]); } $product->update($request->all()); return redirect('product')->with(['message' => 'Success']); }
public function store(Request $request) { $input = $request->all(); $picture = Picture::create(['name' => $input['background_image_name'], 'url' => 'cover']); $project = Publish::create(['user_id' => Auth::user()->id, 'category_id' => $input['category_id'], 'picture_id' => $picture->id, 'is_active' => 1, 'type' => 'project', 'title' => $input['title'], 'desc' => $input['desc'], 'content' => $input['content'], 'url' => $input['url']]); mkdir(base_path() . '/public/assets/images/projects/' . $project->id, 0777); $file = base_path() . '/public/assets/images/projects/' . $project->id . '/cover.jpg'; $img = Image::make($input['background_image']); $img->save($file); $tools = explode('_', $input['tags']); if ($tools[0] != '') { foreach ($tools as $tool) { $tool = Tool::create(['term' => $tool]); PublishTool::create(['publish_id' => $project->id, 'tool_id' => $tool->id]); } } for ($i = 0; $i < 6; $i++) { if (isset($input['image_' . $i])) { $unique_name = md5(microtime()); $picture = Picture::create(['name' => $input['image_name_' . $i], 'url' => $unique_name]); PublishPicture::create(['publish_id' => $project->id, 'picture_id' => $picture->id]); $file = base_path() . '/public/assets/images/projects/' . $project->id . '/' . $unique_name . '.jpg'; $img = Image::make($input['image_' . $i]); $img->save($file); } } return redirect()->route('projects'); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $picture = Picture::find($id); $picture->fill($request->all()); $picture->save(); return back()->withMessage('Picture is updated!'); }
static function createpicture(Request $request, $id) { $img = $request->file('thumbnail'); $ext = $img->getClientOriginalExtension(); $uri = str_random(12) . '.' . $ext; $img->move(env('UPLOAD_PATH', './uploads'), $uri); Picture::create(['uri' => $uri, 'size' => $img->getClientSize(), 'type' => $ext, 'product_id' => $id]); }
/** * Show the form for creating a new resource. * * @return Response */ public function create() { $newPicture = Picture::create(['name' => 'pictures', 'image' => 'no_image.png', 'latitude' => 21.0289428, 'longitude' => 105.8512668, 'user_id' => 1, 'category_id' => 1]); $newPicture->user_id = 1; $newPicture->category_id = 1; $newPicture->save(); dd('ok'); }
public function getPicture($id) { $picture = Picture::findOrFail($id); $path = storage_path('app/pictures/pic_' . $picture->id); $response = Response::make(File::get($path)); $response->header('Content-Type', 'image/png'); return $response; }
public function getByExif(Picture $picture) { $exif = $picture->getExif(); if (isset($exif['SectionsFound']) && @strpos($exif['SectionsFound'], 'GPS')) { try { $lat = $this->getGps($exif['GPSLatitude']); $lng = $this->getGps($exif['GPSLongitude']); if ($lat && $lng) { $this->getByLatLng($lat, $lng); return true; } } catch (\Exception $e) { return false; } } return false; }
public function singlePicture($id) { $user = Auth::user(); $picture = Picture::whereIn('gallery_id', function ($query) use($user) { $query->select('id')->from('galleries')->where('user_id', $user->id); })->where('id', $id)->first(); return response()->json(['data' => $picture->toArray()]); }
public function getIndex(MapRequest $request, $lat = null, $lng = null, $lat2 = null, $lng2 = null) { $pictures = collect([]); if ($lat2 === null) { $pictures = Picture::byGeoPoint($lat, $lng)->get(); } else { $pictures = Picture::byBoundingBox($lat, $lng, $lat2, $lng2)->get(); } return response((new PictureMapMapper($pictures))->getItems())->header('Content-Type', 'application/json')->header('Access-Control-Allow-Origin', '*')->header('Access-Control-Allow-Methods', 'GET')->header('Access-Control-Allow-Headers', 'Content-Type, X-Auth-Token, Origin'); }
public function store(Request $request) { $input = $request->all(); $picture = Picture::create(['name' => $input['background_image_name'], 'url' => 'cover']); $article = Publish::create(['user_id' => Auth::user()->id, 'category_id' => $input['category_id'], 'picture_id' => $picture->id, 'is_active' => 1, 'type' => 'article', 'title' => $input['title'], 'desc' => $input['desc'], 'content' => $input['content']]); mkdir(base_path() . '/public/assets/images/articles/' . $article->id, 0777); $file = base_path() . '/public/assets/images/articles/' . $article->id . '/cover.jpg'; $img = Image::make($input['background_image']); $img->save($file); return redirect()->route('articles'); }
public function postPicture(Request $request) { $this->validate($request, ['description' => 'required|max:255', 'photo' => 'required|mimes:jpeg,gif,png']); $date = Carbon::now(); $filename = Input::file('photo')->getClientOriginalName(); $rand = rand(11111, 99999); Image::make(Input::file('photo'))->save('img/users/' . $rand . '-' . $filename); $count = Picture::where('user_id', Auth::user()->id)->count(); if ($count == 5) { $count = Picture::where('user_id', Auth::user()->id)->orderBy('created_at', 'asc')->take(1)->delete(); } $inputData = $request->all(); $img = new Picture(); $img->picture_url = '/img/users/' . $rand . '-' . $filename; $img->description = $inputData['description']; $img->isDish = 0; $img->user_id = Auth::user()->id; $img->save(); return redirect()->route('dashboard')->withSuccess('succesfully added a picture'); }
/** * Get all Trips from user that allready started sorted by end-date (desc) * * @return mixed */ public function getTripsForMyTrips() { $trips = $this->trips()->latest('end')->alreadyStarted()->get(); //retrieving path of featured images foreach ($trips as $trip) { if ($trip['pic']) { $pic = Picture::findOrFail($trip['pic']); $trip['picName'] = $pic->filename; } } return $trips; }
/** * Run the database seeds. * * @return void */ public function run() { $url = "https://randomuser.me/api/?results=50&key=" . env('RANDOMUSER_API_KEY') . "&nat=us"; $json = file_get_contents($url); $json_data = json_decode($json, true); file_put_contents('current_userset.txt', $json); foreach ($json_data['results'] as $result) { $user = new User(); $user->email = $result['user']['email']; $user->password = bcrypt($result['user']['password']); $user->first_name = ucfirst($result['user']['name']['first']); $user->last_name = ucfirst($result['user']['name']['last']); $user->phone_number = $result['user']['phone']; $user->number_of_degrees = 1; $user->save(); $degree = new Degree(); $degree->year = rand(1923, 2010); $degree->user_id = $user->id; $faculties = array('arts_and_science', 'education', 'engineering_and_applied_science', 'health_science', 'law', 'business', 'graduate_studies', 'policy_studies'); $types = array('ba', 'bcmp', 'bfa', 'bphe', 'bs', 'bsce', 'bcomm', 'msc', 'phd'); $degree->faculty = $faculties[array_rand($faculties)]; $degree->type = $types[array_rand($types)]; $degree->primary_degree = true; $degree->save(); $pictureUploadResult = \Cloudinary\Uploader::upload($result['user']['picture']['large']); if ($pictureUploadResult == null) { echo "Error uploading picture for " . $result['user']['name']['first'] . $result['user']['name']['last']; continue; } $picture = new Picture(); $picture->description = ""; $picture->url = $pictureUploadResult['secure_url']; $picture->cloudinary_public_id = $pictureUploadResult['public_id']; $picture->save(); $junction = new UserPictureBridge(); $junction->user_id = $user->id; $junction->picture_id = $picture->id; $junction->save(); } }
public function run() { $files = Storage::allFiles(); foreach ($files as $file) { Storage::disk('local')->delete($file); } $products = Product::all(); foreach ($products as $product) { $uri = str_random(12) . '_370x235.jpg'; Storage::put($uri, file_get_contents('http://lorempixel.com/futurama/370/235/')); Picture::create(['product_id' => $product->id, 'uri' => $uri, 'title' => $this->faker->name]); } }
/** * returns Picture with prev and next Picture as attributes for single navigation * * @param $id * @return mixed */ public static function getSinglePic($id) { $pic = Picture::findOrFail($id); $all = Picture::where('trip_entry_id', $pic->trip_entry_id)->orderBy('id')->get(); $index = $all->search($pic); $count = $all->count(); if ($index != 0) { $prev = $all[$index - 1]; $pic->prev = $prev; } if ($index + 1 != $count) { $next = $all[$index + 1]; $pic->next = $next; } return $pic; }
/** * Run the database seeds. * * @return void */ public function run() { // Eloquent::unguard(); DB::table('pictures')->delete(); DB::statement("ALTER TABLE pictures AUTO_INCREMENT=1"); $files = Storage::allFiles(); foreach ($files as $file) { Storage::delete($file); } $products = Product::all(); foreach ($products as $product) { $uri = str_random(12) . '_370x235.jpg'; Storage::put($uri, file_get_contents('http://lorempixel.com/futurama/370/235')); Picture::create(['product_id' => $product->id, 'uri' => $uri, 'title' => $this->facker->name, 'type' => 'jpg', 'size' => 200]); } }
public function run() { $files = Storage::allFiles(); foreach ($files as $file) { Storage::delete($file); //sert a vider le dossier upload si on relance un refresh //pour éviter de stocker 15 images + 15 images ect... } $products = Product::all(); //recupere tous les produits precedement creer dans un tableau foreach ($products as $product) { $uri = str_random(12) . '_370x235.jpg'; //str_random fait un chaine de caractere de 12 Storage::put($uri, file_get_contents('http://lorempixel.com/futurama/370/235/')); Picture::create(['product_id' => $product->id, 'uri' => $uri, 'title' => $this->faker->name]); } }
/** * Run the database seeds. * * @return void */ public function run() { // Eloquent::unguard(); DB::table('pictures')->delete(); DB::statement("ALTER TABLE avatars AUTO_INCREMENT=1"); $dirUploads = public_path(env('UPLOAD_PICTURES', 'uploads')); $files = File::allFiles($dirUploads); foreach ($files as $file) { File::delete($file); } $products = Product::all(); foreach ($products as $product) { $uri = str_random(12) . '_370x235.jpg'; $fileName = file_get_contents('http://lorempixel.com/futurama/370/235'); $pathDirectory = $dirUploads . DIRECTORY_SEPARATOR . $uri; FILE::put($pathDirectory, $fileName); $mime = mime_content_type($dirUploads . DIRECTORY_SEPARATOR . $uri); Picture::create(['product_id' => $product->id, 'uri' => $uri, 'title' => $this->facker->name, 'mime' => $mime, 'size' => 200]); } }
public function image($request, $product) { if ($request->input('supImag') == 'true') { Storage::delete($product->picture->uri); $product->picture->delete(); } if ($request->file('thumnail')) { if ($product->picture) { Storage::delete($product->picture->uri); $product->picture->delete(); } $name = $request->input('name'); $im = $request->file('thumnail'); $ext = $im->getClientOriginalExtension(); $num_prod = $product->id; $num_prod = intval($num_prod); $uri = str_random(12) . '.' . $ext; $im->move(env('UPLOAD_PATH', './uploads'), $uri); Picture::create(['product_id' => $num_prod, 'size' => $im->getClientSize(), 'uri' => $uri, 'type' => $ext, 'title' => $name]); } }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Requests\ProductRequest $request, $id) { $tags = $request->input('tags'); $product = Product::find($id); if (!empty($tags)) { // $product->tags()->detach(); // $product->tags()->attach($tags); // equivalent à $product->tags()->sync($tags); } else { $product->tags()->detach(); // s'il n y a pas de tags ou tags décochés } // gestion image et $picture = $product->picture; if ($request->input('delete_img') == 1) { if (!is_null($picture)) { Storage::delete($picture->uri); // supprime le fichier physiquement $picture->delete(); // supprime la picture en BDD dans la table pictures } } if (!is_null($request->file('thumbnail'))) { // on remet ce bout de code ci-dessous au cas ou boutton supprimer non coché et nouvelle image uploadée if (!is_null($picture)) { Storage::delete($picture->uri); // supprime le fichier physiquement $picture->delete(); // supprime la picture en BDD dans la table pictures } $im = $request->file('thumbnail'); // extension de l'image $ext = $im->getClientOriginalExtension(); $uri = str_random(12) . '.' . $ext; // dd($im->move(env('UPLOAD_PATH', './uploads'), $uri)); $im->move(env('UPLOAD_PATH', './uploads'), $uri); // Exception renvoyée par le framework si problem # Bien veiller aux fillables de Picture pour que ça marche ci-dessous # et !! si on a deja 'move' notre image, getSize ne marche plus, il faut getClientSize Picture::create(['uri' => $uri, 'size' => $im->getClientSize(), 'type' => $ext, 'product_id' => $product->id]); } $product->update($request->all()); return redirect('product')->with(['alert' => 'done', 'message' => 'update produit']); }
/** * get all entries associated with a trip containing the filename for the featured image of the entry * * @return mixed */ public function getEntriesWithPic() { $entries = $this->tripEntries()->get(); //retrieving path of featured images foreach ($entries as $entry) { if ($entry['pic']) { $pic = Picture::findOrFail($entry['pic']); $entry['picName'] = $pic->filename; } } return $entries; }
/** * Find pictures by category and send them back in json-format. * * parameter: http-request $request * returns: json-response */ public function findByCategory(Request $request) { // Pictures are ordered from most liked to least liked by default. $pictures = Picture::where('category', $request->category)->orderBy('likes', 'desc')->get(); return response()->json($pictures); }
public function getDefaultPicture($type) { return Picture::where(['defaultpic' => 1, 'type' => $type])->get(); }
protected function storeImage(Art $art, $img, $isMaster) { $destinationPath = "auction/img/"; $extension = $img->getClientOriginalExtension(); $fileName = rand(11111, 99999) . '.' . $extension; // renameing image random name //fullpath = path to picture + filename + extension $fullPath = $destinationPath . $fileName; $img->move($destinationPath, $fileName); $picture = new Picture(); $picture->url = '/' . $fullPath; $picture->art_id = $art->id; $picture->isMaster = $isMaster; $picture->save(); }
$keys = $collections->keys(); for ($i = 0; $i < $keys->count(); $i++) { $items->push($collections->get($keys[$i])); } } else { $items = collect($query); } return $items; //return view('picture.listpics',compact('collections')); }); Route::get('/picture/massedit', function () { $query = Picture::all(); return view('picture.massedit', compact('query')); }); Route::get('/picture/photoeditor', function () { $query = Picture::all(); return view('picture.photoeditor', compact('query')); }); Route::get('/picture/manager', function () { $query = Picture::all(); return view('picture.manager', compact('query')); }); Route::any('/picture/upload', function () { $query = Picture::all(); return view('picture.upload', compact('query')); }); Route::any('/picture/delete2', function () { $query = Picture::all(); return view('picture.delete2', compact('query')); }); Route::resource('picture', 'PictureController');
/** * Implements picture like and dislike (voting). Ensures that user is * allowed to vote by checking database records. * * parameter: http-request * returns: vote success in json-format (also possible return trough * validation error) */ public function votePicture(Request $request) { // May cause early return with error condition in json-format. $this->validate($request, ['picture_id' => 'required|integer|exists:pictures,id', 'operation' => 'required|min:4|max:7']); $pictureVotes = PictureVotes::where('user_id', Auth::user()->id)->where('picture_id', $request->picture_id)->get(); if ($pictureVotes->count() > 0) { // User has voted on this picture before. $isSuccessful = false; } else { // A fresh vote. $picture = Picture::findOrFail($request->picture_id); $isSuccessful = true; if ($request->operation == 'like') { $picture->likes = $picture->likes + 1; } else { $picture->dislikes = $picture->dislikes + 1; } $picture->save(); // Database insert into pictures-table. // Store new picture vote into database. $pictureVotes = new PictureVotes(); $pictureVotes->user_id = Auth::user()->id; $pictureVotes->picture_id = $request->picture_id; $pictureVotes->voted = true; // Not needed $pictureVotes->vote_type = $request->operation; $pictureVotes->save(); // Database insert into picture_votes-table. } return response()->json(['is_successful' => $isSuccessful]); }
function get_all_images_from_property_id($property_id) { /* Find the junction table entries for pictures of this property */ $photo_ids = PropertyPictureBridge::where('property_id', $property_id)->get(); $images = array(); /* Get all the photos of this property */ if (count($photo_ids) < 1) { $placeholder = new Picture(); $placeholder->url = env('PLACEHOLDER_IMAGE_URL'); $placeholder->cloudinary_public_id = env('PLACEHOLDER_IMAGE_PUBLIC_ID'); array_push($images, $placeholder); } else { foreach ($photo_ids as $photo_id) { array_push($images, Picture::find($photo_id->picture_id)); } } return $images; }