Example #1
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $business = Business::where('slug', '=', $id)->first();
     $owner = User::find($business->owner_id);
     $reviews = Review::where('business_id', '=', $business->id)->get();
     return view('businesses.show', ['title' => $business->name, 'business' => $business, 'owner' => $owner, 'reviews' => $reviews]);
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $review = Review::find($id);
     $business = Business::where('id', '=', $review->business_id)->first();
     $average_rating = Review::where('business_id', '=', $business->id)->avg('rating');
     $business->average_rating = round($average_rating, 1);
     $business->save();
     $review->delete();
     return Redirect::route('businesses.show', $business->slug);
 }
Example #3
0
 /**
  * Gets average rating for business
  *
  */
 public function averageRating()
 {
     return round(Review::where('business_id', '=', $this->id)->avg('rating'), 1);
 }