join('line_lists', 'paint_follow_ups.line', '=', 'line_lists.line_no') ->where(function($query) { $query->whereNull('line_lists.painting_cycle') ->orWhere('line_lists.painting_cycle', ''); }); if(isset($lineNumber)){ $deletedCount = $deletedCount->where('paint_follow_ups.line', $lineNumber); } $deletedCount = $deletedCount->delete(); Log::debug("$deletedCount rows deleted from paint_follow_ups table"); ?>