PHPackages                             chrispecoraro/php-sanity - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. chrispecoraro/php-sanity

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

chrispecoraro/php-sanity
========================

A collection of utilities for use with Sanity.io

1159PHP

Since May 18Pushed 1y ago1 watchersCompare

[ Source](https://github.com/chrispecoraro/PHP-Sanity)[ Packagist](https://packagist.org/packages/chrispecoraro/php-sanity)[ RSS](/packages/chrispecoraro-php-sanity/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

PHP-Sanity
==========

[](#php-sanity)

PHP Sanity is a PHP class providing convience utility functions for performing mutations to  schemas. This requires the sanity-php client.

### Usage:

[](#usage)

// instantiation:

```
$sanity = new Sanity('1a2b3c4d', 'production',
'skY70CML0Ovm3GfPqQKeLtBNnS....',
'2019-01-29');`
```

---

`create()` is useful for creating a single record from an array or object:

```
$arr = ['Tim', 'Jones'];
$sanity->create("employee", $arr, ["firstName","lastName"]);
```

---

`create()` also works with an object:

```
$sanity->create("employee", (object)$arr,["firstName","lastName"]);
```

---

`createFromString()` creates a single document given a delimited string.

```
$sanity->createFromString("employee",'Ralph|Peters',["firstName","lastName"],'|');
```

---

` batchCreate()` is useful for importing from an array of arrays or objects

```
$docs = [
    ['Bob', 'Jones'],
    ['Ron', 'Philips']
];
$sanity->batchCreate("employee", $docs, ["firstName","lastName"]);
$sanity->batchCreate("employee", (object)$docs, ["firstName","lastName"]);
```

---

`batchCreateFromFile()` is useful for importing from a delimited file

```
// example file:
// records.csv:
//    Bob|Jones
//    Ron|Philips

$sanity->batchCreateFromFile("employee", "./records.csv", ["firstName","lastName"], "|");
```

---

`copy()` copies the document source field to the target field's value. // This is useful for back filling fields

```
$sanity->copy('employee','telephone','cellular');
```

---

`attach()` attaches (using a reference) a document (via id) to a document.

```
$sanity->attach(fieldName: 'group',
relatedFieldId: '1991fe09-b54c-4e35-9d32-15413863c3b6',
    documentId: 'fb5b618b-47e4-40c7-964b-2e479cb33');
```

---

`attachImage()` works with the Document ID as a parameter

```
$sanity->attachImage('/home/bob/Documents/Bob-Photo.jpeg',
    documentId: 'fb5b618b-47e4-40c7-964b-2e479cb33');
```

---

`attachImage()` also works with a documentId set as a class property

```
$sanity->setDocumentId("fb5b618b-47e4-40c7-964b-29cb33c4");
$sanity->attachImage("/home/bob/Documents/avatar.jpg");
```

---

`attachImage()` also works with an image URL

```
$sanity->setDocumentId("fb5b618b-47e4-40c7-964b-279cb33c4");
$sanity->attachImage("https://picsum.photos/400/300");
```

---

`all()` is a shortcut equivalent a fetch using GROQ //$results = $sanity-&gt;fetch('\*\[\_type=="menuItem"\]');

```
$results = $sanity->all("employee");
```

---

`set()` sets a single field in a document to a given value.

```
$sanity->set("lastName","Jones","fb5b618b-47e4-40c7-964b-2e479cb3c4");
```

---

`deleteAll()` deletes ALL documents of a given schema type.

IMPORTANT: be careful and make a back up (export the dataset first).

```
$sanity->deleteAll('employee');
```

---

`deleteById()` deletes a single documents given its id.

IMPORTANT: be careful and make a back up (export the dataset first).

```
$sanity->deleteById('fb5b618b-47e4-40c7-964b-2e479cb33c');
```

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance26

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity18

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/880860af4ce8d0a4fb5c35faa41523a40210a6dfbb758e88f3d6ba640b568200?d=identicon)[chrispecoraro](/maintainers/chrispecoraro)

---

Top Contributors

[![chrispecoraro](https://avatars.githubusercontent.com/u/307660?v=4)](https://github.com/chrispecoraro "chrispecoraro (31 commits)")

### Embed Badge

![Health badge](/badges/chrispecoraro-php-sanity/health.svg)

```
[![Health](https://phpackages.com/badges/chrispecoraro-php-sanity/health.svg)](https://phpackages.com/packages/chrispecoraro-php-sanity)
```

###  Alternatives

[petrabarus/yii2-googleplacesautocomplete

Google Places Auto Complete input widget for Yii2

106.4k](/packages/petrabarus-yii2-googleplacesautocomplete)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
