Full Table
:key | id | color | mark | price |
---|---|---|---|---|
5 | 5 | Red | Peugeot | 1550 |
14 | 14 | Green | Peugeot | 1200 |
22 | 22 | Blue | Peugeot | 1400 |
31 | 31 | Red | Citroen | 2000 |
45 | 45 | Yellow | Citroen | 1800 |
52 | 52 | Brown | Citroen | 1400 |
67 | 67 | Brown | Nissan | 1700 |
71 | 71 | Green | Nissan | 1750 |
89 | 89 | Red | Nissan | 1500 |
Update (price > 1500 => price / 10)
:key | id | color | mark | price |
---|---|---|---|---|
5 | 5 | Red | Peugeot | 155 |
14 | 14 | Green | Peugeot | 1200 |
22 | 22 | Blue | Peugeot | 1400 |
31 | 31 | Red | Citroen | 200 |
45 | 45 | Yellow | Citroen | 180 |
52 | 52 | Brown | Citroen | 1400 |
67 | 67 | Brown | Nissan | 170 |
71 | 71 | Green | Nissan | 175 |
89 | 89 | Red | Nissan | 1500 |
$table->updateMultiple( expr()->gt('price', 1500), function ($row) { $row['price'] /= 10; return $row; } )
Delete (price < 180 or color = "brown")
:key | id | color | mark | price |
---|---|---|---|---|
14 | 14 | Green | Peugeot | 1200 |
22 | 22 | Blue | Peugeot | 1400 |
31 | 31 | Red | Citroen | 200 |
45 | 45 | Yellow | Citroen | 180 |
89 | 89 | Red | Nissan | 1500 |
$table->deleteMultiple( expr()->or( expr()->lt('price', 180), expr()->eq('color', 'brown', false) ) )
Update an existing element
:key | id | color | mark | price |
---|---|---|---|---|
14 | 14 | Green | Peugeot | 1200 |
22 | 22 | Blue | Peugeot | 1400 |
31 | 31 | Red | Citroen | 200 |
45 | 45 | Yellow | Citroen | 2000 |
89 | 89 | Red | Nissan | 1500 |
$table->update( [ 'id' => 45, 'price' => '2000', ] )
Update the same element but with its key
:key | id | color | mark | price |
---|---|---|---|---|
14 | 14 | Green | Peugeot | 1200 |
22 | 22 | Blue | Peugeot | 1400 |
31 | 31 | Red | Citroen | 200 |
45 | 45 | Yellow | Citroen | 2100 |
89 | 89 | Red | Nissan | 1500 |
$table->update(['price' => '2100'], 45)
Insert an element
:key | id | color | mark | price |
---|---|---|---|---|
14 | 14 | Green | Peugeot | 1200 |
22 | 22 | Blue | Peugeot | 1400 |
31 | 31 | Red | Citroen | 200 |
45 | 45 | Yellow | Citroen | 2100 |
89 | 89 | Red | Nissan | 1500 |
90 | 90 | Green | BMW | 3000 |
$table->insert( [ 'mark' => 'BMW', 'price' => '3000', 'color' => 'Green', ] )
Upsert an element
:key | id | color | mark | price |
---|---|---|---|---|
14 | 14 | Green | Peugeot | 1200 |
22 | 22 | Blue | Peugeot | 1400 |
31 | 31 | Red | Citroen | 200 |
45 | 45 | Yellow | Citroen | 2100 |
89 | 89 | Red | Nissan | 1500 |
90 | 90 | Green | BMW | 3000 |
91 | 91 | Red | BMW | 3100 |
$table->upsert( [ 'mark' => 'BMW', 'price' => '3100', 'color' => 'Red', ] )
Upsert the same element
:key | id | color | mark | price |
---|---|---|---|---|
14 | 14 | Green | Peugeot | 1200 |
22 | 22 | Blue | Peugeot | 1400 |
31 | 31 | Red | Citroen | 200 |
45 | 45 | Yellow | Citroen | 2100 |
89 | 89 | Red | Nissan | 1500 |
90 | 90 | Green | BMW | 3000 |
91 | 91 | Yellow | BMW | 3100 |
$table->upsert( ['color' => 'Yellow'], $table->getLastInsertedKey() )
Delete one element
:key | id | color | mark | price |
---|---|---|---|---|
14 | 14 | Green | Peugeot | 1200 |
22 | 22 | Blue | Peugeot | 1400 |
45 | 45 | Yellow | Citroen | 2100 |
89 | 89 | Red | Nissan | 1500 |
90 | 90 | Green | BMW | 3000 |
91 | 91 | Yellow | BMW | 3100 |
$table->delete(31)