Example #1
0
 function attr_info($id)
 {
     $attr = DB::table('attraction')->where('link_item_id', $id)->first();
     $item = DB::table('item')->where('item_id', $id)->first();
     $photo = DB::table('photo_gallery')->where('link_item_id', $id)->first();
     $review = DB::table('review')->where('link_item_id', $id)->get();
     $location = DB::table('location')->where('link_item_id', $id)->first();
     $ratings = DB::table('rating_relation')->where('item_id', $id)->get();
     $likes = Like::join('review', 'review.review_id', '=', 'like_relation.review_id')->where('link_item_id', $item->item_id)->select('review.review_id', 'likeOrDislike')->get();
     /*find avg_rating*/
     $avg_rating = 0.0;
     $i = 0;
     foreach ($ratings as $rat) {
         $i++;
         $avg_rating = $avg_rating + $rat->rating;
     }
     if ($i != 0) {
         $avg_rating = $avg_rating / $i;
     }
     $user = array();
     foreach ($review as $rev) {
         $Auser = DB::table('users')->where('user_id', $rev->link_user_id)->first();
         array_push($user, $Auser);
     }
     return view('info_attr', ['attr' => $attr, 'item' => $item, 'photo' => $photo, 'review' => $review, 'location' => $location, 'user' => $user, 'avg_rating' => $avg_rating, 'rating_count' => $i, 'likes' => $likes]);
 }