I define a query to delete a table in database. After that i want to show a message that the query was run successfully. How can I check it with an if
statement?
$query = DB::table('user_users')->delete();
return view('datenbank');
When you use delete
with the query builder it will return the number of affected rows.
Your if statement would just need to look something like:
$query = DB::table('user_users')->delete();
if ($query) {
//query successful
}
If you want to be more explicit you could do if ($query > 0) {}
If anything goes wrong with the query (an error) it will throw an Exception
which will mean that no rows have been affected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With