/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     // Get Faker instance
     $faker = Faker\Factory::create();
     // Create a number of users
     for ($numRatings = 0; $numRatings < 250; $numRatings++) {
         UserCommentRating::forceCreate(['comment_id' => rand(1, 25), 'rating' => $faker->boolean(70)]);
     }
 }
Exemplo n.º 2
0
 /**
  * @param $comment_id
  *
  * @return array
  */
 public function rating($comment_id)
 {
     // Get ratings
     $ratings = UserCommentRating::select(['rating', \DB::raw('COUNT(*) AS numRatings')])->where('comment_id', $comment_id)->groupBy('rating')->get()->toArray();
     if (!$ratings) {
         return ResponseHelper::write(404, 1000, 'The requested comment does not exist.');
     }
     // Get transformer
     $transformer = new UserCommentRatingTransformer();
     // Return transformed collection
     return $transformer->transformCollection($ratings);
 }