/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(CreateRatingRequest $request, $id) { $restaurant = Restaurant::findOrFail($id); $rating = new Rating(); $rating->fill($request->input()); $rating->restaurant()->associate($restaurant); $rating->save(); return $restaurant; }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, RentalUnit $rental, User $user) { $rating = $rental->ratings()->where('from_user', $user->id)->first(); if ($rating == null) { $rating = new Rating(); } $rating->fill(Input::all()); $rating->save(); // $rating->avgRating = $rental->ratings()->avg('rating_points'); return Response::json($rating); }