84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
laravel ORM 一对一、一对多、多对多、原生的MYSQL怎么写?laravel ORM 的with原理是什么?如题
认证高级PHP讲师
class User extends Model{ public function Roles() { return $this->hasOne("App\Role", 'user_id', 'id'); } } class Message extends Model{ public function User() { return $this->belongsTo("App\User", 'user_id', 'id'); } } //Controller 输出sql看 \DB::listen(function($sql,$binds){ dump($sql,$binds); }); $role = User::find(1)->Roles;//一对多类似 //select * from `users` where `id` = 1 limit 1 ; //select * from `roles` where `user_id` = 1 limit 1 ; $mess = Message::with('User')->where('type',$type)->get(); //select *from messages where type=?; 查询出用户id列表 //select * from `users` where `id` in (?);根据id列表查询用户信息
认证高级PHP讲师