mxroute-laravel maintained by community-sdks
MXroute Laravel
Laravel integration for the strictly typed community-sdks/mxroute-php SDK.
Installation
composer require community-sdks/mxroute-laravel
The service provider and facade are discovered automatically. Publish the configuration if you want to customize it:
php artisan vendor:publish --tag=mxroute-config
Add your MXroute credentials to .env:
MXROUTE_API_KEY=your-api-key
MXROUTE_SERVER=your-server.mxrouting.net
MXROUTE_USERNAME=your-username
These optional settings are also available:
MXROUTE_BASE_URL=https://api.mxroute.com
MXROUTE_TIMEOUT=30
MXROUTE_USER_AGENT=my-application/1.0
Usage
Inject the upstream client into a controller, job, command, or service:
use CommunitySDKs\MXRoute\DTOs\Requests\EmailAccounts\CreateEmailAccountRequest;
use CommunitySDKs\MXRoute\MXRouteClient;
final class CreateMailbox
{
public function __construct(private readonly MXRouteClient $mxroute) {}
public function handle(): void
{
$this->mxroute->emailAccounts()->createEmailAccount(
'example.com',
new CreateEmailAccountRequest(
username: 'hello',
password: 'SecurePassword1',
quota: 1024,
),
);
}
}
Or use the facade:
use CommunitySDKs\MXRouteLaravel\Facades\MXRoute;
$domains = MXRoute::domains()->listDomains();
All upstream services and DTOs remain available without an extra abstraction layer. See the upstream SDK documentation for its complete API.
Testing applications that use this package
Replace the client in Laravel's container with a test instance or an SDK client
built with a custom TransportInterface:
$fake = new \CommunitySDKs\MXRoute\MXRouteClient($fakeTransport);
$this->app->instance(\CommunitySDKs\MXRoute\MXRouteClient::class, $fake);
License
The MIT License (MIT).