M
M
Martovitskiy2021-12-02 18:40:09
Laravel
Martovitskiy, 2021-12-02 18:40:09

How to properly write using query builder laravel?

How to rewrite this query using query builder in laravel?

SELECT count(public.events.is_hit) as is_hit, event_date
  FROM public.events group by is_hit, event_date order by is_hit desc;


$query->groupBy('is_hit');
$query->groupBy('event_date');
$query->orderBy('is_hit', $sorting['desc']);


I don't understand how to write SELECT count(public.events.is_hit)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Anton, 2021-12-02
@Martovitskiy

https://laravel.com/docs/8.x/queries#raw-expressions
something like DB::table('public.events')->select('event_date', DB::raw('count( is_hit) as is_hit'))->groupBy('is_hit', 'event_date')->orderBy('is_hit', $sorting['desc'])->get()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question