DB QUERY:
Select * from deviceCategory Where deviceCategory.subCategoryId IN('Select subCategoryId From subCategory where subCategoryName=$value');
这是我尝试过的原始数据库查询。但它不起作用。我想要的是,首先,我需要根据传递给控制器的值从subCategoryId
表中获取subCategory
。使用所选的id,我需要将它与另一个表进行比较,以获得相同的id匹配并获取该表的详细信息。
控制器代码:
public function checkDeviceCategory($value)
{
$users=DB::select('SELECT * FROM deviceCategory WHERE
deviceCategory.subCategoryId IN (SELECT subCategoryId FROM
subCategory WHERE subCategoryName=$value)');
echo $users;
}
SCRIPT代码;
<script>
$(document).ready(function() {
$('.checkDeviceCategory').click(function() {
var value=$(this).text();
if(value)
{
window.location='checkDeviceCategory/' +value;
}
});
});
</script>
这是传递给控制器的值。
答案 0 :(得分:1)
$sub = DB::table('subCategory')
->where('subCategoryName', '=', $value)
->pluck('subCategoryId');
$users = DB::table('deviceCategory')
->whereIn('subCategoryId', $sub)
->get();