0
votes

i have two table with the following details:

Ecourse table

  • id
  • slug
  • title
  • logo
  • description
  • price
  • status

Traffics table

  • id
  • ecourse_id
  • date
  • amount
  • type_traffic

I want to display ecourse data with the amount of traffic per day using eloquent laravel. What's the solution?

Thank you

1
Please provide create table structures, sample data and expected result. stackoverflow.com/help/minimal-reproducible-exampleErsoy

1 Answers

0
votes
$ecourses = Ecourse::with(['traffics' => function($q){
    $q->groupBy('date')
      ->selectRaw('sum(amount) as sum, date');
}])->get();

Keep me posted in the comments below. Cheers!