---
title: Repository
---

# Repository

<div class="documentation__toc"></div>

## Introduction

Form repositories are used to create an `entry` when creating and to update an `entry` when editing. The repository is guessed based on the type of model used.

> Custom repositories are a rare need.{.note}

If you would like to or need to define the repository yourself you can do so on the form builder.

```php
protected $repository = \Example\Test\FancyFormRepository::class;
```

You can also set an instantiated repository on the builder dynamically:

```php
$builder->setRepository(app(MyFormRepository::class);
```

The form repository must implement `\Anomaly\Streams\Platform\Ui\Form\Contract\FormRepositoryInterface` and implement the following methods:

```php
/**
 * Find an entry or return a new one.
 *
 * @param $id
 * @return mixed
 */
public function findOrNew($id);

/**
 * Save the form.
 *
 * @param  FormBuilder $builder
 * @return bool|mixed
 */
public function save(FormBuilder $builder);
```
