06.10.2016 Views

laravel-5

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Database: Getting Started 516<br />

1 $affected = DB::update('update users set votes = 100 where name = ?', ['John']);<br />

Running A Delete Statement<br />

The delete method should be used to delete records from the database. Like update, the number of<br />

rows deleted will be returned:<br />

1 $deleted = DB::delete('delete from users');<br />

Running A General Statement<br />

Some database statements should not return any value. For these types of operations, you may use<br />

the statement method on the DB facade:<br />

1 DB::statement('drop table users');<br />

Listening For Query Events<br />

If you would like to receive each SQL query executed by your application, you may use the listen<br />

method. This method is useful for logging queries or debugging. You may register your query listener<br />

in a service provider:<br />

1

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!