Reputation: 1479
I have this query
SELECT ANY_VALUE(id) as id, title FROM `major` where university_id=1 group BY `title` order by id asc
I want to convert it into Laravel Query , I have a model majors and the function as follow
public static function retrieveByUniversityIDForWeb($universityId){
return self::select(DB::raw('ANY_VALUE(id) as id, title'))->from('major')->where('university_id', $universityId)->orderBy('id','desc')->simplePaginate(6);
}
but its not returning me the results , query works in phpmyadmin. Any idea what I missed?
Upvotes: 0
Views: 72
Reputation: 11906
You're declaring the method on your model which references its table by default. Also there's no need for using ANY_VALUE
in your query. If you need it for some reason then you can change the select below to selectRaw('ANY_VALUE(id) as id, title')
public static function retrieveByUniversityIDForWeb($universityId)
{
return self::select('id', 'title')
->where('university_id', $universityId)
->orderBy('id', 'desc')
->simplePaginate(6);
}
Upvotes: 1