your1 / laravel-sparql
A SPARQL based Eloquent model and Query builder for Laravel
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/your1/laravel-sparql
Requires
- php: ^8.2
- illuminate/container: ^12.0
- illuminate/database: ^12.0
- illuminate/events: ^12.0
- illuminate/support: ^12.0
- madbob/easyrdf-on-guzzle: 0.3.0
- ml/json-ld: ^1.2
- nesbot/carbon: ^3.0
Requires (Dev)
- doctrine/dbal: ^3.0|^4.0
- laravel/pint: ^1.13
- nunomaduro/larastan: ^3.0
- orchestra/testbench: ^10.0
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.0
This package is auto-updated.
Last update: 2025-10-24 14:04:32 UTC
README
A lean, production-ready Laravel Eloquent adapter for SPARQL triple stores. Query and manage RDF data using familiar Laravel patterns.
Overview
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.
Key Features
- 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
Requirements
- PHP 8.0+
- Laravel 9.0+
- A SPARQL 1.1 endpoint (Apache Jena Fuseki, Virtuoso, Blazegraph, etc.)
Installation
Install via Composer:
composer require solid-data-workers/laravel-sparql
The service provider will automatically register a sparql database driver with Laravel's database manager.
Quick Start
1. Configure Your SPARQL Endpoint
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/sparql
2. Define a Model
use 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']; }
3. Start Using It
// 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();
Documentation
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
Philosophy
- 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
Credits
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.
License
MIT License. See LICENSE for details.
Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions