Exception or error:
I have three tables in my database name, sms_content, sms_content_categories and categories.
Table sms_content_categories contains “categories_id” and “sms_content_id”. While categories contains, “id”, “title”. I want to get “title” from categories title on basis of “categories_id”.
Basically i am using it in datatables and i getting error.
SQLSTAT[HY00]: General error: 2031 (Sql: select ‘title from categories where ‘id’=?)
Here is my code:
$categoryID = SmsContentCategories::where('sms_content_id', $smsContentID)->pluck('categories_id')->toArray();
$categoryName = Category::where('id', $categoryID)->pluck('title')->toArray();
I want to get title from categories.
How to solve:
I want to get “title” from categories title on basis of “categories_id”.
Not tested but this should work:
$categoryIds = SmsContentCategories::whereIn('sms_content_id', $smsContentID)->pluck('categories_id');
$categoryTitles = Category::whereIn('id', $categoryId)->pluck('title');