public function userPhotos()
 {
     $tags = Tag::where('id', '>', 0)->get();
     $phototags = PhotoTag::where('image_id', '>', 0)->get();
     $images = Image::where('user_id', '=', Auth::user()->id)->orderBy('created_at', 'desc')->paginate(10);
     return view('user.photos')->with(['images' => $images, 'tags' => $tags, 'phototags' => $phototags]);
 }
 public function searchImage(Request $request)
 {
     $images = Image::where('title', 'like', "%" . $request->input('title') . "%");
     $tags = Tag::where('id', '>', 0)->get();
     $phototags = PhotoTag::where('image_id', '>', 0)->get();
     $requestSave['title'] = $request->input('title');
     $requestSave['typeCheck'] = $request->input('typeCheck');
     $requestSave['type'] = $request->input('type');
     $requestSave['ownerCheck'] = $request->input('ownerCheck');
     $requestSave['owner'] = $request->input('owner');
     $requestSave['ownerCheck'] = $request->input('sizeCheck');
     $requestSave['owner'] = $request->input('size');
     if ($request->input('typeCheck') != null) {
         $types = $_GET['type'];
         foreach ($types as $type) {
             $ptags = PhotoTag::where('tag_id', 'like', "%" . $type . "%")->get();
             $arr = array();
             foreach ($ptags as $ptag) {
                 array_push($arr, $ptag->image_id);
             }
             $images = $images->whereIn('id', $arr);
         }
     }
     if ($request->input('ownerCheck') != null) {
         $users = User::where('username', 'like', "%" . $request->input('owner') . "%")->get();
         $arra = array();
         foreach ($users as $user) {
             array_push($arra, $user->id);
         }
         $images = $images->whereIn('user_id', $arra);
     }
     if ($request->input('sizeCheck') != null) {
         if ($request->input('size') == 1) {
             $images->where('size', '<', 1000000);
         } elseif ($request->input('size') == 2) {
             $images->where('size', '>=', 1000000)->where('size', '<=', 2000000);
         } elseif ($request->input('size') == 3) {
             $images->where('size', '>', 3000000);
         }
     }
     $images = $images->paginate(10);
     $images->setPath('/searchimage');
     if (Auth::check()) {
         $votes = Auth::user()->votes()->get();
         return view('search')->with(['images' => $images, 'tags' => $tags, 'votes' => $votes, 'phototags' => $phototags, 'requestSave' => $requestSave]);
     } else {
         return view('search')->with(['images' => $images, 'tags' => $tags, 'phototags' => $phototags, 'requestSave' => $requestSave]);
     }
 }
 private function attachTagsToNewPhoto($photoId, $tags)
 {
     $photo = Photo::where('id', $photoId)->get();
     foreach ($tags as $tag) {
         $tag = Tag::where('tag_name', $tag)->first();
         PhotoTag::create(array('photo_id' => $photoId, 'tag_id' => $tag->id));
     }
 }