# Asset Container Repository

To work with the AssetContainer Repository, use the following Facade:

```php
use Statamic\Facades\AssetContainer;
```

## Methods

| Methods | Description |
| ------- | ----------- |
| `all()` | Get all AssetContainers |
| `find($id)` | Get AssetContainer by `id` |
| `findByHandle($handle)` | Get AssetContainer by `handle` |
| `findOrFail($id)` | Get AssetContainer by `id`. Throws an `AssetContainerNotFoundException` when the asset container cannot be found. |
| `queryAssets()` | Query Builder for the AssetContainer's [Assets](/repositories/asset-repository.md) |
| `make()` | Makes a new AssetContainer instance |

:::tip
The `id` is the same as `handle` while using the default Stache driver.
:::

## Querying

While the `AssetContainer` Repository does not have a Query Builder, you can still query for Assets _inside_ AssetContainers with the `queryAssets` method. This approach can be useful for retrieving Assets with an existing AssetContainer object.

```php
$videos = AssetContainer::find('videos');

$videos->queryAssets()
    ->where('series', 'stranger-things')
    ->get();
```

When an asset container can't be found, the `AssetContainer::find()` method will return `null`. If you'd prefer an exception be thrown, you may use the `findOrFail` method:

```php
AssetContainer::findOrFail('videos');
```

## Creating

Start by making an instance of an asset container with the `make` method. You can pass the handle into it.

```php
$container = AssetContainer::make('assets');
```

You may call additional methods on the container to customize it further.

```php
$container
  ->title('Assets')
  ->allowDownloading(true)
  ->allowMoving(true)
  ->allowRenaming(true)
  ->allowUploads(true)
  ->createFolders(true)
  ->searchIndex('assets');
```

Finally, save it.

```php
$container->save();
```
