Utilities for ElectricSQL in Laravel
You can install the package via Composer:
composer require matfire/laravel-electricsqlYou may publish all of the package's resources at once:
php artisan vendor:publish --tag="laravel-electricsql"Or, you may publish each resource individually:
php artisan vendor:publish --tag="laravel-electricsql-config"You can use laravel-electricsql in two ways:
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.
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"]);
}
}Please see CHANGELOG for more information on what has changed recently.
Thank you for considering contributing to Laravel Electricsql! Please review our contributing guide to get started.
Please review our security policy on how to report security vulnerabilities.
Laravel Electricsql is open-sourced software licensed under the MIT license.