06.10.2016 Views

laravel-5

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Eloquent: Getting Started 565<br />

1 App\Flight::destroy(1);<br />

2<br />

3 App\Flight::destroy([1, 2, 3]);<br />

4<br />

5 App\Flight::destroy(1, 2, 3);<br />

Deleting Models By Query<br />

Of course, you may also run a delete query on a set of models. In this example, we will delete all<br />

flights that are marked as inactive:<br />

1 $deletedRows = App\Flight::where('active', 0)->delete();<br />

Soft Deleting<br />

In addition to actually removing records from your database, Eloquent can also “soft delete” models.<br />

When models are soft deleted, they are not actually removed from your database. Instead, a<br />

deleted_at attribute is set on the model and inserted into the database. If a model has a nonnull<br />

deleted_at value, the model has been soft deleted. To enable soft deletes for a model, use the<br />

Illuminate\Database\Eloquent\SoftDeletes trait on the model and add the deleted_at column<br />

to your $dates property:<br />

1

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

Saved successfully!

Ooh no, something went wrong!