Example #1
0
 public function photoStore($id)
 {
     $file = Input::file('image_url');
     $data = Input::only(['title', 'image_url']);
     $rules = ['title' => 'required', 'image_url' => 'required|image|mimes:jpeg,jpg|max:1000'];
     $validation = Validator::make($data, $rules);
     if ($validation->fails()) {
         return Redirect::back()->withInput()->withErrors($validation->messages());
     } else {
         $getRealPath = 'images/assets/' . date('Y') . '/';
         $photo = new Photo($data);
         $photo->gallery_id = $id;
         $photo->image_url = $getRealPath . $data['image_url']->getClientOriginalName();
         $photo->save();
         if ($photo->save()) {
             $i = 0;
             $info = explode(".", $file->getClientOriginalName());
             $newFile = $file->getClientOriginalName();
             while (file_exists($getRealPath . $newFile)) {
                 $i++;
                 $newFile = $info[0] . "(" . $i . ")" . "." . $info[1];
             }
             $file->move($getRealPath, $newFile);
             if ($newFile != $photo->image_url) {
                 $photo->image_url = $getRealPath . $newFile;
                 $photo->save();
             }
         }
     }
     return Redirect::back()->with(['confirm' => 'Se inserto el registro correctamente.']);
 }
 public function run()
 {
     $faker = Faker::create();
     foreach (range(1, 10) as $index) {
         $title = $faker->sentence($nbWords = 6);
         $gallery = Gallery::create(['title' => $title, 'body' => $faker->text($maxNbChars = 200), 'slug' => \Str::slug($title), 'available' => true]);
         foreach (range(1, 5) as $index) {
             Photo::create(['title' => $faker->sentence($nbWords = 6), 'image_url' => $faker->randomElement(['images/assets/2014/4.jpg', 'images/assets/2014/5.jpg', 'images/assets/2014/6.jpg']), 'gallery_id' => $gallery->id]);
         }
     }
 }