A lean, production-ready Laravel Eloquent adapter for SPARQL triple stores. Query and manage RDF data using familiar Laravel patterns.
Laravel SPARQL brings the power of RDF triple stores to Laravel with an Eloquent-style interface that feels native to Laravel developers. Built on the original Illuminate Database package by Taylor Otwell.
- Familiar Eloquent API - Use standard Laravel patterns like
where(),get(),first(),save(),delete() - Hybrid Approach - Scalars for single values, arrays for multi-values (no unnecessary Collections)
- RDF Extensions - Language tags, multi-valued properties, and URI mappings when you need them
- Batch Operations - Efficient bulk insert/update/delete operations
- Sync Trait - Easily sync regular Eloquent models to SPARQL endpoints
- No Magic - Explicit model definitions, no dynamic class generation
- Production Ready - 100% test coverage, optimized for performance
- PHP 8.0+
- Laravel 9.0+
- A SPARQL 1.1 endpoint (Apache Jena Fuseki, Virtuoso, Blazegraph, etc.)
Install via Composer:
composer require solid-data-workers/laravel-sparqlThe service provider will automatically register a sparql database driver with Laravel's database manager.
Add to config/database.php:
'connections' => [
'sparql' => [
'driver' => 'sparql',
'endpoint' => env('SPARQL_ENDPOINT', 'http://localhost:3030/test/sparql'),
'auth' => [
'type' => 'digest',
'username' => env('SPARQL_USERNAME'),
'password' => env('SPARQL_PASSWORD'),
],
'namespaces' => [
'schema' => 'http://schema.org/',
'foaf' => 'http://xmlns.com/foaf/0.1/',
],
],
],Add to .env:
SPARQL_ENDPOINT=http://localhost:3030/test/sparqluse LinkedData\SPARQL\Eloquent\Model;
class Person extends Model
{
protected $connection = 'sparql';
protected $table = 'http://schema.org/Person';
protected $propertyUris = [
'name' => 'http://schema.org/name',
'email' => 'http://schema.org/email',
'age' => 'http://schema.org/age',
];
protected $fillable = ['name', 'email', 'age'];
protected $casts = ['age' => 'integer'];
}// Create
$person = new Person();
$person->id = 'http://example.com/person/1';
$person->name = 'John Doe';
$person->email = 'john@example.com';
$person->save();
// Query
$adults = Person::where('age', '>', 18)->get();
$john = Person::where('name', 'John')->first();
// Update
$person->age = 31;
$person->save();
// Delete
$person->delete();For comprehensive guides and examples, see:
- Usage Guide - Core concepts, CRUD operations, queries, RDF features, batch operations, and syncing regular Eloquent models
- API Reference - Complete API documentation for all classes and methods
- Development Guide - Setup, testing, and development instructions
- Simple is Better - Minimal complexity, maximum clarity
- No Magic - Explicit over implicit, predictable behavior
- Performance First - Optimized for production workloads
- Laravel Native - Feels like standard Eloquent
Original Author: Roberto Guido - Created the foundational Laravel SPARQL adapter and maintained it as part of the Solid Data Workers project.
Original Repository: https://gitlab.com/solid-data-workers/laravel-sparql
Original Licenses: MIT License and Creative Commons Attribution 3.0 Unported
This fork preserves all original copyright and attribution while adding significant enhancements and modernizations.
Built on Laravel's Illuminate Database package by Taylor Otwell.
MIT License. See LICENSE for details.
- Issues: GitHub Issues
- Discussions: GitHub Discussions