A JOIN With Additional Conditions Using Query Builder or Eloquent

后端 未结 6 701
抹茶落季
抹茶落季 2020-12-04 09:08

I\'m trying to add a condition using a JOIN query with Laravel Query Builder.



        
6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-04 09:35

    If you have some params, you can do this.

        $results = DB::table('rooms')
        ->distinct()
        ->leftJoin('bookings', function($join) use ($param1, $param2)
        {
            $join->on('rooms.id', '=', 'bookings.room_type_id');
            $join->on('arrival','=',DB::raw("'".$param1."'"));
            $join->on('arrival','=',DB::raw("'".$param2."'"));
    
        })
        ->where('bookings.room_type_id', '=', NULL)
        ->get();
    

    and then return your query

    return $results;

提交回复
热议问题