Maison  >  Questions et réponses  >  le corps du texte

php - laravel ORM如何多表查询的时候再加分页

表1有 id uname

表2有uid,但是没有uname,

要求查出 表1.id=表2.uid 并且输出表一的uname,并对结果分页

大体语法类似User::hasOneRecord()::pagination(12)

do you know?

高洛峰高洛峰2735 Il y a quelques jours913

répondre à tous(1)je répondrai

  • PHP中文网

    PHP中文网2017-04-11 09:57:42

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

    OR

               
    $result = table1::leftJoin('table2', 'table1.id', '=', 'table2.uid')->select('table1.uname')->paginate(12);
    

    répondre
    0
  • Annulerrépondre