【发布时间】:2018-06-28 08:42:21
【问题描述】:
我有两张表 tbl_law_master 和 tbl_law_sub_master 在这两个表上都有一个名为 assigned_to 的列,该列存储用户的 id。
我的任务是通过加入 tbl_law_master 的 law_id,从 tbl_law_sub_master 获取特定用户 id 的 sublaw。
这是我的代码,
$law_id = $_GET['law_id'];
$sublaw = DB::table('tbl_law_sub_master')
->select('tbl_law_sub_master.*', 'tbl_law_master.lm_id', 'tbl_law_master.law_name', 'tbl_law_master.id as lawId')
->leftJoin('tbl_law_master', 'tbl_law_master.id', '=', 'tbl_law_sub_master.lm_id')
->where('tbl_law_sub_master.lm_id', $law_id)
->orderBy('type_of_event', 'asc')
->orderBy('section', 'asc')
->orderBy('rules', 'asc')
->orderBy('notification', 'asc')
->orderBy('circular', 'asc')->get();
if (!in_array(Auth::user()->role, [1, 7]))
{
$sublaw = $sublaw->where('tbl_law_master.assigned_to', Auth::user()->id);
}
它向我显示 error 为
调用数组上的成员函数 where()
【问题讨论】:
-
那有什么问题?
-
@MahdiYounesi 问题是我的代码没有返回特定用户 ID 的数据
标签: php mysql laravel join controller