/** * Execute the job. * * @return void */ public function handle() { if ($this->username != '') { $rating = new Rating(); $rating->content_id = $this->content->id; $rating->rating = $this->rating; $rating->username = $this->username; $rating->save(); } }
public function rate() { $id = \Request::input('id', 0); $rating = \Request::input('rating', 0); $content = Content::find($id); if ($content) { if ($content->ratings()->count() == 0) { $new_rating = new Rating(); $new_rating->content_id = $content->id; $new_rating->rating = $content->rating; $new_rating->save(); } $avg_rating = ($content->ratings()->sum('rating') + $rating) / ($content->ratings()->count() + 1); $content->rating = $avg_rating; $content->save(); $job = new UpdateRatingCount($id, $rating, \Request::server('PHP_AUTH_USER')); $this->dispatch($job); } }