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

How to add paging when laravel ORM queries multiple tables

WBOY
Release: 2016-08-18 09:15:42
Original
2660 people have browsed it

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>
Copy after login

OR

<code>           
$result = table1::leftJoin('table2', 'table1.id', '=', 'table2.uid')->select('table1.uname')->paginate(12);
</code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template