如何在laravel中进行此查询

时间:2014-06-26 23:27:58

标签: laravel

我需要在laravel中使用带有take和skip功能的查询。

SELECT
    parlimen.`name` AS parlimen_name,
    parlimen.`code` AS parlimen_code,
    member.email AS email,
    member.`name` AS `name`,
    member.phone_no AS phone_no,
    member.fax_no AS fax,
    member.image AS image,
    party.`group` AS party_group,
    party.short_form AS party_short_form,
    party.logo AS party_logo,
    state.`name` AS state_name,
    state.id AS state_id
FROM member, parlimen
    INNER JOIN parlimenmember ON parlimen.id = parlimenmember.parlimen_id
    INNER JOIN party ON parlimenmember.party_id = party.id
    INNER JOIN state ON state.id = parlimen.state_id
ORDER BY
    parlimen_code ASC

1 个答案:

答案 0 :(得分:0)

我尝试过这个并取得了成功。希望能指导其他

$result = DB::table('parlimenmember')
            ->join('parlimen', 'parlimenmember.parlimen_id', '=', 'parlimen.id')
            ->join('member', 'parlimenmember.member_id', '=', 'member.id')
            ->join('party', 'parlimenmember.party_id', '=', 'party.id')
            ->join('state', 'state.id', '=', 'parlimen.state_id')
            ->select(
            'parlimen.name AS parlimen_name', 
            'parlimen.code AS parlimen_code', 
            'member.email AS email',
            'member.name AS name',
            'member.phone_no AS phone_no',
            'member.fax_no AS fax',
            'member.image AS image',
            'party.group AS party_group',
            'party.short_form AS party_short_form',
            'party.logo AS party_logo',
            'state.name AS state_name'
            )->orderBy('parlimen.code', 'ASC')->take($take)->skip($skip)->get();