Adding Updating Records

Cuisine’s Record class can be used to both fetch data and, as you will see, to update or delete data. This class was made to work together with custom tables you can add using Cuisine’s migration system

In Cuisine we do this with the Record class, which is available through Cuisine’s wrapper system. Just include the following namespace:

use Cuisine\Wrappers\Record

Inserting data

Inserting data is as easy as this example:

$productMetaId = Record::insert( 'product_meta', $args );

This example will create a new row in the ‘product_meta’ table and return this row’s primary key.

If you make sure the array $args in this example is an exact key-value pair of your database table, everything will work out-of-the-box. If you’ve placed restrictions on your database table (like non-nullable fields) and you forget to include a key in your $args that can’t be null, you’ll get a MySQL error.


Inserting data with or without a primary key can be done by using the insertOrUpdate() function. If there’s no primary key given, a new record will be created. Here’s an example:

$args = [ 'id' => 1, 'price' => 100 ];
$productMeta = Record::insertOrUpdate( 'product_meta', $args );

This example will update a record with the ID of 1 and set it’s price-field to 100.


Updating a specific field is very easy, just include the row’s primary key:

Record::update( 'product_meta', 1, [ 'price' => 100 ]);

This function call will update the price of a row of product_meta with the primary key of 1.