Skip to content
Advertisement

Laravel 4.2: Convert a SQL select statement to Eloquent statement

I have the following DB::select statement:

JavaScript

Which its result will be something like:

JavaScript

what is the equivalent statement using the Eloquent model?

This is what I have so far:

JavaScript

Advertisement

Answer

You can use this:

JavaScript

You need to use DB::raw when using count in your query’s select, because otherwise it will get quoted by PDO.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement