1. Go to this page and download the library: Download getaviato/laravel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
getaviato / laravel example snippets
use Aviato\Laravel\Context\ActionContext;
use Aviato\Laravel\Context\FormContext;
use Aviato\Laravel\Context\HookContext;
use Aviato\Laravel\Facades\Aviato;
Aviato::action('customers', 'Refund last invoice')
->single() // or ->bulk(), ->global()
->description('Refunds the latest paid invoice')
->form(
['type' => 'object', 'properties' => ['reason' => ['type' => 'string']], ']);
// or ->error(), ->html(), ->file($name, $mime, $content), ->redirect(url: …), ->webhook(…)
});
// Dynamic forms: called when the form opens and after each change.
Aviato::action('customers', 'Plan change')
->form(['type' => 'object', 'properties' => ['plan' => ['type' => 'string'], 'confirm' => ['type' => 'boolean']]])
->resolveForm(fn (FormContext $context) => $context->resolve(
values: $context->changedField === 'plan' && $context->value('plan') === 'team' ? ['confirm' => true] : [],
))
->execute(fn (ActionContext $context) => $context->success('Plan changed'));
Aviato::computedField('customers', 'fullName')
->dependsOn('first_name', 'last_name')
->compute(fn (array $records) => array_map(fn ($r) => "{$r['first_name']} {$r['last_name']}", $records));
Aviato::hook('customers', 'before', 'update')->run(fn (HookContext $context) =>
($context->values['plan'] ?? null) === 'enterprise'
? $context->reject('Enterprise plans are set by sales')
: $context->proceed());
Aviato::segment('customers', 'vip')->resolve(fn () => ['filter' => ['plan' => 'team']]);
Aviato::search('customers')->resolve(fn (string $query) => ['name' => ['$ilike' => "%{$query}%"]]);
Aviato::writeOverride('customers', 'fullName')->write(fn ($value) => array_combine(['first_name', 'last_name'], explode(' ', $value, 2) + ['', '']));
Aviato::chart('customersByPlan', 'customers')->compute(fn (?array $filter) => ['mark' => 'bar', 'data' => ['values' => []]]);
use Aviato\Laravel\Context\DatasourceContext;
use Aviato\Laravel\Context\DatasourceQuery;
use Aviato\Laravel\Definitions\CustomCollectionDefinition;
use Aviato\Laravel\Exceptions\DatasourceException;
Aviato::datasource()
->collection('tickets', fn (CustomCollectionDefinition $collection) => $collection
->field('id', 'number', nullable: false, readOnly: true)
->field('subject', 'string', nullable: false)
->field('status', 'enum', enumValues: ['open', 'closed'])
// What `list` does itself; the agent does the rest in memory.
->capabilities(filterOperators: ['eq', 'in'], sort: true, count: true))
->list(fn (DatasourceQuery $query, DatasourceContext $context) => ['records' => Helpdesk::search($query), 'total' => Helpdesk::count($query)])
->create(fn (array $values) => $values['subject'] ?? null
? Helpdesk::create($values)
: throw new DatasourceException('A subject is
use Aviato\Laravel\Facades\Aviato;
it('refunds the last invoice', function () {
$aviato = Aviato::fake()->withRecords('customers', [['id' => 42, 'email' => '[email protected]']]);
$aviato->executeAction('customers', 'Refund last invoice', [42], ['reason' => 'Duplicate'])
->assertSuccess('Refunded [email protected]')
->assertInvalidated(['invoices']);
$aviato->actingAs(['role' => 'viewer'])
->executeAction('customers', 'Refund last invoice', [42])
->assertError();
$aviato->data()->assertNothingWritten();
});
use Aviato\Laravel\Integrations\ZendeskPlugin;
use Aviato\Laravel\Integrations\RecordBinding;
Aviato::use((new ZendeskPlugin('northstar', 'ZENDESK_WIDGET_TOKEN', true))
->tickets('customers', 'support', new RecordBinding('zendesk_user_id')));