jeudi 31 décembre 2015

GroupBy Query Laravel 5.1

I'm having problem in fetching the data using groupBy, I don't where I'm wrong, I have done it many times before, but today I'm wrong some where and I don't know where. Following is the Table from which I want to select the Data:

Table Name: user_questions

id | user_id | message | read_status_user | read_status_support | answered

Now suppose if one user sends more than one messages, then user_id will be repeated, So to want all the message from one particular user I'm firing the query like following:

UserQuestion::groupBy('user_id')->get();

This should give me the result like

user_id = 1 > message1
user_id = 1 > message2
....
user_id = 1 > message...(if any)

user_id = 2 > message1
user_id = 2 > message2
..... 
So on...

But this is always giving me only one message from the particular user. I don't know why. Is there any mistake? I have tried another queries too, but all are giving me the same result.

Please help me with this. Everybody's help will be highly appreciated. Thanks to all of you in advance.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire