Inserting Or Updating Models

Save

The most common way to create or update a model is to use the save method. This will create a new model if there is no ID. Otherwise, it will update an existing model if an ID is provided.

use SureCart\Models\Product;

$product = new Product([
	'name' => 'iPhone',
	'description' => 'iPhone is a smartphone'
]);
$product->save();

Building queries

To query by specific parameters, you can use the where method. This method sends query parameters over the API and returns the matching records.

use SureCart\Models\Product;
$archived_products = Product::where([
	'archived' => false
])->get();

Pagination

You can paginate and retrieve subsequent pages of results by using the paginate method. This method takes two parameters: page and per_page. The default pagination per_page limit is set to 100.

use SureCart\Models\Product;

$archived_products = Product::where([
	'archived' => false
])->paginate([
	'per_page' => 20,
	'page' => 2
]);

Result:

[
	'object' => 'product',
	'pagination' => [
		'count' => 100,
		'limit' => 20,
		'page' => 2
	],
	'data' => [
		// 20 products
		[
			'id' => '8ba8d60f-5277-4e6b-807c-dee8166446d5',
			...
		]
		...
	]
]