1. 首页
  2. 数据库
  3. 其它
  4. PHP中Laravel 关联查询返回错误id的解决方法

PHP中Laravel 关联查询返回错误id的解决方法

上传者: 2020-12-23 01:41:08上传 PDF文件 52.34KB 热度 17次
在 Laravel Eloquent 中使用 join 关联查询,如果两张表有名称相同的字段,如 id,那么它的值会默认被后来的同名字段重写,返回不是期望的结果。例如以下关联查询: PHP $priority = Priority::rightJoin('touch', 'priorities.touch_id', '=', 'touch.id') ->where('priorities.type', 1) ->orderBy('priorities.total_score', 'desc') ->orderBy('touch.created_at', 'desc') ->get()
下载地址
用户评论