Laravel在透视表的基础上从表中获取标题



我的数据库名称中有三个表,sms_content、sms_content_categories和categories。

表sms_content_categories包含"categories_id"one_answers"sms_content_id"。而类别包含"id"、"title"。我想在"categories_id"的基础上从类别标题中获得"title"。

基本上,我在数据表中使用它,我得到了错误。SQLSTAT[HY00]:一般错误:2031(Sql:从"id"=?的类别中选择"title"(

这是我的代码:

$categoryID = SmsContentCategories::where('sms_content_id', $smsContentID)->pluck('categories_id')->toArray();
$categoryName = Category::where('id', $categoryID)->pluck('title')->toArray(); 

我想从类别中获得标题。

我想在"categories_id"的基础上从类别标题中获得"title"。

未测试,但这应该有效:


$categoryIds = SmsContentCategories::whereIn('sms_content_id', $smsContentID)->pluck('categories_id');
$categoryTitles = Category::whereIn('id', $categoryId)->pluck('title');

最新更新