---
title: Usage in PHP
order: 70
---

# Usage in PHP

Everything the tag can do is available in PHP through the `Distill` facade.

[TOC]

---

## Querying

`Distill::query()` returns a query builder with camel cased methods that match the [tag parameters](tag#parameters), plus all the usual `where`, `orderBy`, `limit`, `offset`, `get`, `first`, `count` and `paginate` methods you'd use with any Statamic query builder:

```php
use JackSleight\StatamicDistill\Facades\Distill;

$videos = Distill::query($entry)
    ->type('set:video')
    ->where('url', 'like', '%youtube.com%')
    ->orderBy('title')
    ->get();
```

The source can be an entry, term, asset or user, a `Value` object (`$entry->augmentedValue('builder')`), a Laravel collection, a plain array or an object. The query methods are:

* **type (string|array)**  
  The type to match.
* **path (string|array)**  
  The path to match.
* **expand (string|array)**  
  Which types to expand and walk into.
* **depth (integer)**  
  Sets both `minDepth` and `maxDepth`.
* **minDepth (integer)**  
  The minimum depth to find items from.
* **maxDepth (integer)**  
  The maximum depth to find items from.
* **unique (boolean)**  
  Filter out duplicate entries, terms, assets and users.
* **includeSource (boolean)**  
  Whether to include the source value itself as an item.
* **includeDisabled (boolean)**  
  Whether to include disabled Replicator and Bard sets.

:::note
Unlike the tag, pipe delimited strings aren't split here. To match more than one type or path pass an array instead.
:::

---

## Items

The results are a collection of `Item` objects. Each one is augmentable, so you can read its fields as properties or array keys, or convert the whole thing to an array. The `info` object is there too:

```php
$item->info->type;              // set:video
$item->info->path;              // builder.2
$item->info->parent;            // The containing item, or null

$item->title;                   // The set's title field, augmented
$item['title'];                 // Same thing
$item->toAugmentedArray();      // Everything, including info

$item->originalValue('title');  // The underlying Value object
```

---

## Text and Bard

`Distill::text()`, `Distill::bard()` and their `extract*` counterparts are covered on the [Text & Bard](text-and-bard#in-php) page.
