/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function voteDown($id, Request $request) { $rating = new MovieRating(); $rating->movie_id = $id; $rating->rating = -1; $rating->save(); $movie = Movie::findOrFail($id); return response()->json(['success' => true, 'score' => $movie->rating]); }
/** * Get Total Rating */ public function getRatingAttribute() { return MovieRating::select(DB::raw('SUM(rating) AS rating'))->where('movie_id', $this->id)->first()->rating; }