我有这个查询
SELECT * FROM books b
INNER JOIN categories c ON b.category_id = c.id
WHERE c.category_name = 'Comics'
因此通过参数
传递SELECT * FROM books b
INNER JOIN categories c ON b.category_id = c.id
WHERE c.category_name = ?
我在Laravel中试过这样的
writer::join('categories','categories.id','=','writers.category_id')
->where('categories.category_name','Comics')
->get();
并带参数
writer::join('categories','categories.id','=','writers.category_id')
->where(['categories.category_name' => $cat])
->get();
我没有在Laravel中获得任何数据!我有什么错误吗?
答案 0 :(得分:1)
请改为尝试:
writer::join('categories','categories.id','=','writers.category_id')
->where([
['categories.category_name', '=', $cat]
])->get();
或
writer::join('categories','categories.id','=','writers.category_id')
->where('categories.category_name', $cat)
->get();