ThinkPHP 多表关联
-
thinkphp如何关联查询
### 使用withJoin方法,,“,$result = Db::table(‘a’), ˃withJoin(‘b’, function($query) {, $query˃where(‘a.id’, ‘=’, ‘b.a_id’);, }), ˃select();,`,,### 使用关联模型,,`,class User extends Model,{, public function orders(), {, return $this˃hasMany(Order::class, ‘user_id’, ‘id’);, },},,$user = User::find(1);,foreach ($user˃orders as $order) {, echo $order˃name;,},“