Installation
composer require triagens/arangodb
Add the service provider to config/app.php:
'providers' => [
// ...
Triagens\ArangoDb\ArangoDbServiceProvider::class,
],
Configuration Publish the config file:
php artisan vendor:publish --provider="Triagens\ArangoDb\ArangoDbServiceProvider"
Update .env with your ArangoDB credentials:
ARANGODB_HOST=your-arango-host
ARANGODB_PORT=8529
ARANGODB_USER=root
ARANGODB_PASSWORD=your-password
First Query Inject the client into a controller or service:
use Triagens\ArangoDb\Client;
public function __construct(Client $arangodb)
{
$this->client = $arangodb;
}
public function fetchDocuments()
{
$collection = $this->client->collection('your_collection');
$documents = $collection->all();
return $documents;
}
CRUD Operations
// Create
$document = $collection->insert(['name' => 'Test', 'value' => 123]);
// Read
$document = $collection->findOne(['name' => 'Test']);
// Update
$collection->update($document['_key'], ['value' => 456]);
// Delete
$collection->delete($document['_key']);
AQL Queries
$query = $this->client->query('
FOR doc IN your_collection
FILTER doc.value > 100
RETURN doc
');
$results = $query->execute();
Graph Operations
$graph = $this->client->graph('your_graph');
$vertices = $graph->vertices('your_vertex_collection');
$edges = $graph->edges('your_edge_collection');
// Add edge
$graph->addEdge('vertex1', 'vertex2', ['type' => 'relation']);
Transactions
$this->client->transaction(function ($tx) {
$tx->collection('collection1')->insert(['data' => 'test']);
$tx->collection('collection2')->insert(['data' => 'test2']);
});
jenssegers/arangodb alongside triagens/arangodb for ORM-like syntax if preferred.$collection->listen('document.inserted', function ($event) {
Log::info('New document inserted:', $event->document);
});
batch() for bulk operations:
$collection->batch(function ($batch) {
$batch->insert(['name' => 'Batch1']);
$batch->insert(['name' => 'Batch2']);
});
Connection Issues
ARANGODB_HOST and ARANGODB_PORT are correct (default: 8529).ARANGODB_SSL=true if connecting via HTTPS.Query Performance
FULLTEXT or complex AQL queries in loops; cache results when possible.EXPLAIN in AQL queries to analyze performance:
$query = $this->client->query('EXPLAIN FOR doc IN your_collection RETURN doc');
Collection Existence
if (!$this->client->hasCollection('your_collection')) {
$this->client->createCollection('your_collection');
}
Transaction Isolation
'debug' => env('ARANGODB_DEBUG', false),
$this->client->setLogger(function ($query) {
Log::debug('ArangoDB Query:', ['query' => $query]);
});
Custom Middleware Override request/response handling:
$client->middleware(function ($request) {
$request->setOption('timeout', 10000); // Custom timeout
});
Query Builders
Extend the QueryBuilder class for domain-specific methods:
class CustomQueryBuilder extends \Triagens\ArangoDb\QueryBuilder
{
public function byName($name)
{
return $this->where('name', $name);
}
}
Event Customization Subscribe to ArangoDB events globally:
$client->on('collection.created', function ($event) {
// Post-creation logic
});
ARANGODB_DATABASE in .env to avoid hardcoding.ARANGODB_USER and ARANGODB_PASSWORD are set. For JWT, configure:
'auth' => [
'driver' => 'jwt',
'token' => env('ARANGODB_JWT_TOKEN'),
],
How can I help you explore Laravel packages today?