Installation
composer require aboutcoders/file-distribution
Add the service provider to config/app.php:
Aboutcoders\FileDistribution\FileDistributionServiceProvider::class,
Publish Config
php artisan vendor:publish --provider="Aboutcoders\FileDistribution\FileDistributionServiceProvider"
Locate the config at config/file-distribution.php.
First Use Case Distribute a file to multiple users via email:
use Aboutcoders\FileDistribution\Facades\FileDistribution;
$filePath = storage_path('app/large-report.pdf');
$recipients = ['user1@example.com', 'user2@example.com'];
FileDistribution::send($filePath, $recipients);
File Distribution via Email
FileDistribution::send(
$filePath,
$recipients,
['subject' => 'Your Document', 'message' => 'Please find attached']
);
resources/views/vendor/file-distribution/email.blade.php).max_chunk_size).Queue-Based Distribution Use Laravel queues to avoid timeouts for large files:
FileDistribution::queueSend($filePath, $recipients);
queue:work to be running.Custom Storage Integration Extend for S3, Dropbox, etc.:
FileDistribution::extend('s3', function ($app) {
return new S3FileDistributor($app['aws']);
});
Notifiable for user-specific emails:
$user->notify(new FileDistributionNotification($filePath));
FileDistributionSent events to log or audit:
event(new FileDistributionSent($filePath, $recipients));
Route::post('/distribute', function (Request $request) {
$this->authorize('distribute-files');
FileDistribution::send($request->file, $request->recipients);
});
Memory Limits
queueSend() or chunking:
'max_chunk_size' => 50 * 1024 * 1024, // 50MB
memory_limit in php.ini temporarily for testing.Email Attachment Limits
File Permissions
www-data) has read access to distributed files:
chmod -R 755 storage/app/files/
config/file-distribution.php:
'log' => [
'enabled' => true,
'channel' => 'single',
],
php artisan queue:list
php artisan queue:work --once
Custom Distributors
Implement Aboutcoders\FileDistribution\Contracts\Distributor:
class SlackDistributor implements Distributor {
public function distribute($filePath, array $recipients) { ... }
}
Register via:
FileDistribution::extend('slack', function () { return new SlackDistributor(); });
Pre/Post Hooks Use events to modify behavior:
FileDistribution::beforeSend(function ($event) {
if ($event->file->isLarge()) {
$event->setChunkSize(30 * 1024 * 1024);
}
});
Override Templates Publish and modify:
php artisan vendor:publish --tag=file-distribution-views
Edit resources/views/vendor/file-distribution/email.blade.php.
How can I help you explore Laravel packages today?