Home  >  Article  >  Backend Development  >  How to add paging when laravel ORM queries multiple tables

How to add paging when laravel ORM queries multiple tables

WBOY
WBOYOriginal
2016-08-18 09:15:422598browse

Table 1 has id uname

Table 2 has uid, but no uname,

Required to find out Table 1.id = Table 2.uid and output the uname of Table 1, and paginate the results

The general syntax is similar to User::hasOneRecord()::pagination(12)

do you know?

Reply content:

Table 1 has id uname

Table 2 has uid, but no uname,

Required to find out Table 1.id = Table 2.uid and output the uname of Table 1, and paginate the results

The general syntax is similar to User::hasOneRecord()::pagination(12)

do you know?

<code>$result = DB::table('表1')
            ->join('表2', '表1.id', '=', '表2.uid')
            ->select('表1.uname')
            ->paginate(12);
</code>

OR

<code>           
$result = table1::leftJoin('table2', 'table1.id', '=', 'table2.uid')->select('table1.uname')->paginate(12);
</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn