gpt4 book ai didi

php - 如何在 laravel php 中内连接表

转载 作者:行者123 更新时间:2023-11-29 11:03:24 24 4
gpt4 key购买 nike

我有这个查询

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 中没有获取任何数据!我有什么错误吗?

最佳答案

试试这个:

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();

关于php - 如何在 laravel php 中内连接表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41825800/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com