0

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?

1
  • How are you accessing this method on model? Share the controller logic. Commented May 31, 2017 at 16:17

1 Answer 1

1

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);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.