/**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store($gallery_id)
 {
     $input = \Input::all();
     $validation = new \Itestense\LaravelPhotogallery\Validators\Photo();
     if ($validation->passes()) {
         $filename = str_random(10) . time() . "." . \Input::file('path')->getClientOriginalExtension();
         $destination = public_path() . \Config::get('upload_dir') . "/";
         $upload = \Input::file('path')->move($destination, $filename);
         $img = \Image::make($destination . $filename);
         $formats = \Config::get('laravel-photogallery::formats');
         foreach ($formats as $name => $format) {
             $img->resize($format['w'], $format['h'], function ($constraint) {
                 $constraint->aspectRatio();
             });
             $img->save($destination . $name . '/' . $filename, $format['q']);
         }
         if ($upload == false) {
             return \Redirect::to('gallery.photo.create')->withInput()->withErrors($validation->errors)->with('message', 'Errori');
         }
         $photo = new Photo();
         $photo->name = \Input::get('name');
         $photo->description = \Input::get('description');
         $photo->path = $filename;
         $photo->save();
         $g = Gallery::findOrFail(1);
         $photo->galleries()->attach($g);
         //return \Redirect::route("gallery.photo.show", array('id' => $photo->id));
     } else {
         return \Redirect::route('gallery.photo.create')->withInput()->withErrors($validation->errors)->with('message', \Lang::get('gallery::gallery.errors'));
     }
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $gallery = Gallery::findOrFail($id);
     //$photos = $gallery->photos(); This is the right one
     //This is for debugging
     $photos = Photo::all();
     return \View::make('laravel-photogallery::galleries.edit', ['gallery' => $gallery, 'photos' => $photos])->nest('form', 'laravel-photogallery::forms.create-photoingallery', ['gallery' => $gallery, 'photos' => $photos]);
 }
 public function search($key)
 {
     $photos = Photo::where('name', 'LIKE', "%{$key}%")->get();
     return \View::make('laravel-photogallery::photos.search', ['photos' => $photos, 'key' => $key]);
 }