matfire / laravel-electricsql
Utilities for ElectricSQL in Laravel
Fund package maintenance!
Requires
- php: ^8.3
- illuminate/support: ^12.0||^13.0
Requires (Dev)
- larastan/larastan: ^3.9
- laravel/pao: ^1.0
- laravel/pint: ^1.29
- orchestra/testbench: ^10.0||^11.0
- pestphp/pest: ^4.6||^5.0
- pestphp/pest-plugin-laravel: ^4.1||^5.0
- pestphp/pest-plugin-type-coverage: ^4.0||^5.0
- phpstan/extension-installer: ^1.4
README
Laravel Electricsql
Utilities for ElectricSQL in Laravel
Installation
You can install the package via Composer:
composer require matfire/laravel-electricsql
You may publish all of the package's resources at once:
php artisan vendor:publish --tag="laravel-electricsql"
Or, you may publish each resource individually:
Publishing the Configuration File
php artisan vendor:publish --tag="laravel-electricsql-config"
Usage
You can use laravel-electricsql in two ways:
Route Macro
laravel-electricsql exposes a Route macro Route::electric that handles all the logic for you (sending the request, getting the response, stripping the headers) in a single line.
You can use it like so:
Route::electric('/electric/todo', ['table' => 'todos']);
This will register a GET route to the specified url and pass the keyed array as extra parameters to the request.
toResponse
If you want more control and handle some extra logic or effects in your own controller, laravel-electricsql also exposes the toResponse method. Since it's available as a singleton, you can get it in your Controller parameters and use it like so:
use Matfire\LaravelElectricsql\LaravelElectricsql; class TodoElectricController extends Controller { /** * Handle the incoming request. */ public function __invoke(Request $request, LaravelElectricsql $electric) { return $electric->toResponse($request, ["table" => "todos"]); } }
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Thank you for considering contributing to Laravel Electricsql! Please review our contributing guide to get started.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
Laravel Electricsql is open-sourced software licensed under the MIT license.