How to use laravel multi-table query?
phpcn_u1582
phpcn_u1582 2017-05-16 16:47:53
0
1
448

USER table, fields id, name
ACCOUNT table, fields, id,name,account
ORDER table, fields, id,uid,aid,content

How to use related query in laravel with 3 tables

Query the detailed information of the order in the order table through the user id in the user table, and then query the account information of the account account through the aid in the order

phpcn_u1582
phpcn_u1582

reply all (1)
漂亮男人
//在模型中设置关联 class Order extends Model { public function user() { return $this->belongsTo('App\User', 'uid', 'id'); } } //查询出id为1的用户所有的订单,并用with关联出user的信息 $orders= Order::whereHas('user', function ($q) { $q->where('id', 1); })->with('user')->get();

Result

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!