Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Sushant97's avatar

What does a successful Delete Query via Query Builder return?

$result = DB::table('table_name')->where('GENDER', '=', $data['GENDER'])->delete();

this query will delete multiple records. But when I do a dd($result) it always shows 0. How do I ensure my delete query worked properly?

0 likes
1 reply
Nakov's avatar

You can always surround your query call with a try and catch.

try { 
  $result = DB::table('table_name')->where('GENDER', '=', $data['GENDER'])->delete();
} catch(\Illuminate\Database\QueryException $exception){ 
   // $exception->getMessage() - will give you the error if any.
  // Note any method of class PDOException can be called on $exception.
}

Please or to participate in this conversation.