vendredi 5 juin 2020

Laravel eloquent distinct select with possibility to call relation?

I want to select distinct results from one table, the structure is following:

id, user_id, category_id, last_answered_question_id

I have relation for last_answered_question_id called: lastAnsweredQuestion()

My query is:

Answer::select('category_id')->where(['user_id' => $userId])->distinct()->get();

This query works as expected but in this case I can't call relation $answer = lastAnsweredQuestion.

Is there any known way to get distinct items and call relation lastAnsweredQuestion() anyway?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3cEB3n0
via IFTTT

Aucun commentaire:

Enregistrer un commentaire