# Write implementation

{% hint style="success" %}
This is the official documentation of the `forestadmin/laravel-forestadmin` v2+ and `forestadmin/symfony-forestadmin` PHP agents.
{% endhint %}

Making your records editable is achieved by implementing the `create`, `update` and `delete` methods.

The 3 methods take a [filter](/developer-guide-agents-php/data-sources/getting-started/queries/filters.md) as a parameter but note that, unlike the `list` method, there is no need to support paging.

```php
<?php

use ForestAdmin\AgentPHP\DatasourceToolkit\Collection;
use ForestAdmin\AgentPHP\DatasourceToolkit\Components\Caller;
use ForestAdmin\AgentPHP\DatasourceToolkit\Components\Contracts\DatasourceContract;
use ForestAdmin\AgentPHP\DatasourceToolkit\Components\Query\Filters\Filter;
use ForestAdmin\AgentPHP\DatasourceToolkit\Components\Query\Projection\Projection;
use ForestAdmin\AgentPHP\DatasourceToolkit\Schema\ColumnSchema;
use GuzzleHttp\Client;

class MyCollection extends Collection
{
    public function __construct(DatasourceContract $datasource)
    {
        parent::__construct(
            $datasource,
            'MyCollection'
        );

        $this->addField('id', new ColumnSchema(
            // ...
            isReadOnly: true,
        ));

        $this->addField('title', new ColumnSchema(
            // ...
            isReadOnly: false,
        ));

        $this->client = new Client([
            'base_uri' => 'https://my-api/',
            'timeout'  => 5.0,
        ]);
    }

    public function create(Caller $caller, array $records)
    {
        $results = [];

        foreach ($records as $record) {
            try {
                $response = $this->httpClient->post(
                    'my-collection',
                    ['json' => $record]
                );

                $results[] = json_decode($response->getBody()->getContents(), true);
            } catch (\Exception $e) {
                throw new \Exception("Error creating record: " . $e->getMessage(), 0, $e);
            }
        }

        return $results;
    }

    public function update(Caller $caller, Filter $filter, array $patch)
    {
        $recordIds = $this->list($caller, $filter, new Projection('id'));

        foreach ($recordIds as $record) {
            try {
                $this->client->patch("my-collection/{$record['id']}", [
                    'json' => $patch,
                ]);
            } catch (\Exception $e) {
                throw new \Exception("Error updating record {$record['id']}: " . $e->getMessage());
            }
        }

    }

    public function delete(Caller $caller, Filter $filter): void
    {
        $recordIds = $this->list($caller, $filter, new Projection('id'));

        foreach ($recordIds as $record) {
            try {
                $this->client->delete("my-collection/{$record['id']}");
            } catch (\Exception $e) {
                throw new \Exception("Error updating record {$record['id']}: " . $e->getMessage());
            }
        }
    }
}

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.forestadmin.com/developer-guide-agents-php/data-sources/custom/translation/read-write.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
