搜寻中可笑的模棱两可的专栏

时间:2019-05-25 18:32:14

标签: php laravel datatables

我正在使用Laravel 5的可赞美产品。在我的float模型中,我具有此功能

PartnersVehicles

表加载正常,但是当我尝试在搜索框中执行ajax搜索时,我在下面收到此错误

违反完整性约束:1052 where子句中的“ make”列不明确(SQL:从 public static function laratablesQueryConditions($query) { $uid = Auth::id(); //user ID $pid = Partners::where('uid', $uid)->first(); //get partner ID return $query->select('partners_vehicles.id', 'partners_vehicles.year', 'vehicle_makes.make', 'partners_vehicles.model', 'vehicle_colors.color', 'partners_vehicles.created_at') ->join('vehicle_makes', 'vehicle_makes.id', '=', 'partners_vehicles.make') ->join('vehicle_colors', 'vehicle_colors.id', '=', 'partners_vehicles.color') ->where('partners_vehicles.partner_id', $pid->id); } 上的partners_vehicles内部联接vehicle_makes中选择count(*)作为聚合。{{1 }} = vehicle_makesidpartners_vehicles上进行内部连接makevehicle_colors = vehicle_colorsid其中{{1} }。partners_vehicles = 7,而{color如%2%或partners_vehicles如%2%或partner_id如%2%或year如%2% ))

我尝试将选择内容更改为此,但是仍然没有运气

make

有什么解决办法吗?我想念什么?谢谢

1 个答案:

答案 0 :(得分:0)

尝试此代码

public static function laratablesQueryConditions($query)
{
    $uid = Auth::id(); //user ID
    $pid = Partners::where('uid', $uid)->first(); //get partner ID
    $res=DB::table('partners_vehicles')
         ->select('partners_vehicles.id', 'partners_vehicles.year', 'vehicle_makes.make', 'partners_vehicles.model', 'vehicle_colors.color', 'partners_vehicles.created_at')
         ->join('vehicle_makes', 'vehicle_makes.id', '=', 'partners_vehicles.make')
         ->join('vehicle_colors', 'vehicle_colors.id', '=', 'partners_vehicles.color')
         ->where('partners_vehicles.partner_id','=', $pid->id)
         ->get();
   return $res;
}