To work with the with AssetContainer Repository, use the following Facade:
use Statamic\Facades\AssetContainer;
Methods
Methods | Description |
---|---|
all() |
Get all AssetContainers |
find($id) |
Get AssetContainer by id |
findByHandle($handle) |
Get AssetContainer by handle |
queryAssets() |
Query Builder for the AssetContainer's Assets |
make() |
Makes a new AssetContainer instance |
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.
$videos = AssetContainer::find('videos'); $videos->queryAssets() ->where('series', 'stranger-things') ->get();
Creating
Start by making an instance of an asset container with the make
method. You can pass the handle into it.
$container = AssetContainer::make('assets');
You may call additional methods on the container to customize it further.
$container ->title('Assets') ->allowDownloading(true) ->allowMoving(true) ->allowRenaming(true) ->allowUploads(true) ->createFolders(true) ->searchIndex('assets');
Finally, save it.
$container->save();