grschannel/laravel-notification-fax-ir
Laravel notification channel for sending faxes via Fax.ir. Install with Composer and use it in your notification workflows to deliver fax messages from your Laravel application through the Fax.ir service.
Install the Package Run:
composer require grschannel/laravel-faxir-notification
Publish the config file:
php artisan vendor:publish --provider="Grschannel\FaxirNotification\FaxirNotificationServiceProvider" --tag="config"
Configure .env
Add your Fax.ir API credentials:
FAXIR_API_KEY=your_api_key_here
FAXIR_API_SECRET=your_api_secret_here
First Use Case: Sending a Fax
Use the FaxirChannel in a notification class:
use Grschannel\FaxirNotification\Channels\FaxirChannel;
class InvoiceFaxNotification extends Notification
{
public function via($notifiable)
{
return [FaxirChannel::class];
}
public function toFaxir($notifiable)
{
return (new FaxirMessage())
->to('[email protected]') // Fax.ir recipient email
->subject('Invoice Notification')
->content('Your invoice details: ...');
}
}
Integrating with Notifications
Notification class and use FaxirChannel in the via() method.toFaxir() to customize the fax content (subject, body, attachments).Dynamic Recipient Handling
$notifiable->fax_number or a custom attribute to fetch recipients dynamically:
public function toFaxir($notifiable)
{
return (new FaxirMessage())
->to($notifiable->fax_number)
->subject('Dynamic Subject');
}
Attachments
attach() method:
public function toFaxir($notifiable)
{
return (new FaxirMessage())
->to('[email protected]')
->attach(storage_path('app/invoice.pdf'));
}
Queueing Faxes
queue method to avoid blocking:
$user->notify((new InvoiceFaxNotification())->queue());
php artisan queue:work) is running for async fax delivery.try {
$user->notify(new InvoiceFaxNotification());
} catch (\Exception $e) {
\Log::error("Fax failed: " . $e->getMessage());
}
FaxirChannel in unit tests:
$this->fake()->fake(FaxirChannel::class);
API Credentials
FAXIR_API_KEY/FAXIR_API_SECRET in .env is insecure. Use Laravel’s environment variables or a secrets manager.Recipient Format
[email protected]), not phone numbers. Verify the API docs for exact requirements.Attachment Limits
Queue Failures
'failed' => [
'database' => env('DB_CONNECTION', 'mysql'),
],
in config/queue.php.FAXIR_DEBUG=true in .env to log API responses.Http facade to inspect responses:
\Log::debug('Faxir Response:', [
'status' => $response->status(),
'body' => $response->body(),
]);
Customize the Channel
Override the send() method in a service provider to add logic:
public function boot()
{
$this->app->bind(FaxirChannel::class, function ($app) {
return new CustomFaxirChannel($app['config']['services.faxir']);
});
}
Add Retry Logic Extend the channel to retry failed faxes:
use Illuminate\Support\Facades\Retry;
public function send($notifiable, $message)
{
Retry::times(3)->attempt(function () use ($notifiable, $message) {
// Original send logic here
});
}
Webhook Integration Use Fax.ir’s webhooks to track delivery status. Store the webhook secret in config and validate requests in a route:
Route::post('/faxir-webhook', function (Request $request) {
if ($request->header('X-Signature') !== config('services.faxir.webhook_secret')) {
abort(403);
}
// Process webhook data
});
How can I help you explore Laravel packages today?