User Tools

Site Tools


laravel:eloquent

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
laravel:eloquent [2016/12/22 01:24]
dwheele [Inserting New Row]
laravel:eloquent [2016/12/23 00:06] (current)
dwheele [(Laravel) Eloquent Notes]
Line 1: Line 1:
 ====== (Laravel) Eloquent Notes ====== ====== (Laravel) Eloquent Notes ======
 +
 +   * More detail: https://laravel.com/api/5.3/Illuminate/Database/Eloquent/Model.html
  
 ===== Inserting New Row ===== ===== Inserting New Row =====
Line 21: Line 23:
 </code> </code>
  
 +===== Mass Updates =====
 +
 +There are means to update database columns or models. See https://laravel.com/docs/5.3/eloquent
 +
 +===== Delete Row =====
 +
 +https://laravel.com/docs/5.3/eloquent#deleting-models
 +==== If you have the model ==== 
 +
 +To delete a model, call the delete method on a model instance:
 +
 +<code php>
 +  $flight = App\Flight::find(1);
 +  $flight->delete();
 +</code>
 +
 +==== If you have the model's key ====
 +
 +In the example above, we are retrieving the model from the database before calling the delete method. However, if you know the primary key of the model, you may delete the model without retrieving it. To do so, call the destroy method:
 +
 +<code php>
 +  App\Flight::destroy(1);
 +  App\Flight::destroy([1, 2, 3]);
 +  App\Flight::destroy(1, 2, 3);
 +</code>
 +
 +==== Deleting Models By Query ====
 +
 +Of course, you may also run a delete statement on a set of models. In this example, we will delete all flights that are marked as inactive. Like mass updates, mass deletes will not fire any model events for the models that are deleted:
 +
 +<code php>
 +  $deletedRows = App\Flight::where('active', 0)->delete();
 +</code>
  
  
laravel/eloquent.1482369898.txt.gz · Last modified: 2016/12/22 01:24 by dwheele