vendredi 23 février 2018

Laravel Query Builder Error On Query Statement

I am trying to select from two tables . From people table need name and image url and from messages table need the last message sent/received by user.

In people the people id field is unique and message table have people id.

I wrote the simple query which does the task , but when I use the same in laravel it gives me an error saying "access violation"

Here is my sql statement which works when I run:

select people.id, people.first_name, people.last_name, people.img_url, user_messages.message, user_messages.created_at from people inner join user_messages on people.id = user_messages.people_id where people.user_id =1 group by people.id order by user_messages.created_at DESC

And this is the Laravel query with the error

$people = DB::table('people')->select('people.id','people.first_name','people.last_name','people.img_url' ,'user_messages.message','user_messages.created_at')
        ->join('user_messages','people.id','=','user_messages.people_id')
        ->where(['people.user_id' => $user_id])
        ->groupBy('people.id')
        ->orderBy('user_messages.created_at', 'desc')
        ->get();



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire