Level 58
The error in the query is because the orWhere method is being used before the join method. To fix this, move the orWhere method after the join method. Here's the corrected query:
$contactBorrowedThisCar = CarBorrow::query()
->where('borrowed_from_user_id', $userId)
->join('car_owners', 'user_id', '=', 'car_owners.user_id')
->orWhere('car_owners.user_id', $userId)
->where('borrowed_to_user_id', $contactId)
->where('car_id', $carId)
->first();
This query will return the first record that matches the conditions.