Installation
composer require bestnetwork/gsm-box
Register the service provider in config/app.php under providers:
BestNetwork\GSMBox\GSMBoxServiceProvider::class,
Publish Config
php artisan vendor:publish --provider="BestNetwork\GSMBox\GSMBoxServiceProvider" --tag="config"
This generates config/gsm-box.php. Review/modify default settings (e.g., default box type, timeout, retry logic).
Basic Usage
Inject the GSMBox facade or service into a controller/service:
use BestNetwork\GSMBox\Facades\GSMBox;
public function sendSMS()
{
$response = GSMBox::sendSMS(
phone: '+1234567890',
message: 'Hello from GSMBox!'
);
return $response->success() ? 'Sent!' : 'Failed.';
}
Quick Test
Use the gsm-box:test Artisan command to verify connectivity:
php artisan gsm-box:test
SMS Sending
// Basic send
GSMBox::sendSMS('+1234567890', 'Test message');
// With options (e.g., priority, scheduling)
GSMBox::sendSMS('+1234567890', 'Urgent!', [
'priority' => 'high',
'schedule' => now()->addMinutes(5),
]);
Box Management
$boxes = GSMBox::boxes(); // Returns collection of active GSMBox instances
GSMBox::on('box_identifier')->sendSMS(...);
Event Handling
Subscribe to SMS events (e.g., SMSSent, SMSSentFailed) in EventServiceProvider:
protected $listen = [
\BestNetwork\GSMBox\Events\SMSSent::class => [
\App\Listeners\LogSMSSent::class,
],
];
Queue Integration
Configure config/gsm-box.php to use queues for async processing:
'queue' => [
'enabled' => true,
'connection' => 'database',
],
Dispatch jobs manually:
GSMBox::dispatchSMS('+1234567890', 'Queued message');
Logging & Monitoring
'debug' => env('GSMBOX_DEBUG', false),
GSMBox::logs() to retrieve recent activity.BestNetwork\GSMBox\Notifications\SMSMessage to customize notifications:
use BestNetwork\GSMBox\Notifications\SMSMessage;
SMSMessage::to($recipient)->content('Custom content');
GSMBoxHttpClient trait to integrate with external GSM APIs if extending functionality.GSMBox facade in tests:
$this->mock(GSMBox::class)->shouldReceive('sendSMS')->andReturn(new \BestNetwork\GSMBox\Responses\SuccessResponse());
Connection Issues
config/gsm-box.php settings (e.g., timeout, retry_attempts). Check if the GSM box is online:
php artisan gsm-box:status
debug: true and check logs for HTTP errors.Character Limits
GSMBox::sendSMS('+1234567890', str_repeat('a', 200)); // May split into 3 segments
Rate Limiting
throttle in config:
'throttle' => [
'max_attempts' => 10,
'per_minute' => 60,
],
Facade vs. Service Container
GSMBox classes (e.g., new \BestNetwork\GSMBox\GSMBox). Use dependency injection or the facade.Queue Stuck Jobs
failed_jobs table. Retry manually:
php artisan queue:retry all
php artisan gsm-box:list: List all configured boxes.php artisan gsm-box:clear-cache: Clear cached box configurations.log_level in config (debug, info, error) to filter logs..env:
GSMBOX_DEFAULT_BOX=box_identifier
GSMBOX_TIMEOUT=30
Custom Box Types
Extend BestNetwork\GSMBox\Contracts\Box to support new hardware:
class CustomBox implements Box {
public function send($message) { ... }
public function status() { ... }
}
Register in config:
'boxes' => [
'custom' => \App\Boxes\CustomBox::class,
],
Response Handlers Override default responses by binding a custom handler:
GSMBox::extend(function ($app) {
$app->bind(\BestNetwork\GSMBox\Contracts\Response::class, \App\Responses\CustomResponse::class);
});
Middleware
Add middleware to config/gsm-box.php to validate/transform messages:
'middleware' => [
\App\Middleware\ValidateRecipient::class,
],
How can I help you explore Laravel packages today?