vendredi 23 octobre 2015

Converting Raw Query to Laravel Query Builder

I'm trying to convert this raw query into Laravel query builder as I want to use Laravel specific functions:

select * from (select * from messages m
where conversation_id in (select id
     from conversations c
     where 'Test' in (user_one, user_two))
order by id desc) am
group by conversation_id;

I tried the code below. It worked, however I want to be able to use Laravel specific functions such as ->paginate() as well as ->transform(), so although this code below works, I can't use Laravel specific functions:

$messages = \DB::select('select * from
                 (select * from messages m
                  where conversation_id in (select id
                       from conversations c
                       where ? in (user_one, user_two))
                  order by id desc) am
                  group by conversation_id',
                  [\Auth::user()->username]);



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire