$query = DB::table('A')
->leftJoin('B', 'A.id', '=', 'B.A_id')
->whereNull('B.A');
if ($id)
$query->orWhere('A_id', $id);
return $query->get();
DB::connection()->enableQueryLog();
//To get an array of the executed queries, you may use the getQueryLog method:
dd(DB::getQueryLog());
whereNull('B.A');
вместо whereNull('B.A_id');
.