Answer the question
In order to leave comments, you need to log in
Why doesn't groupBy(some_alias) work in laravel5?
There is such a query to the database in SQL
SELECT
COUNT(*),
SUBSTRING_INDEX(SUBSTRING_INDEX(`vars`, '"target":"', -1), '"', 1) AS `target`
FROM `table`
GROUP BY `target`
$table = $table
->select(DB::raw('COUNT(*), SUBSTRING_INDEX(SUBSTRING_INDEX(`vars`, \'"target":"\', -1), \'"\', 1) AS target'))
->groupBy('target');
Answer the question
In order to leave comments, you need to log in
try swapping " ->groupBy('target') " with ->select(DB::raw('COUNT(*), SUBSTRING_INDEX(SUBSTRING_INDEX(`vars`, \'"target":"\', -1) , \'"\', 1) AS target'))
Remove the request logs that give an error and you will immediately understand what's going on.
Typically, Laravel executes nested queries, getting the number of records and relationships first, and then the records themselves.
Please post the logs so I can help you figure out the error.
<expression> as target is explicitly specified in the sql query,
so sql understands in the group by expression what exactly to group by.
In the Laravel expression, there is no column named target. But apparently, the construction "...as name" or "name=<long expression>" should also work there
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question