expresslanding/laravel-filesystem
Extend Laravel Filesystem with unlimited disks (local, S3, SFTP, FTP). Track disk space usage, manage disk statuses, and select an available drive (e.g., random). Includes migrations and config for MySQL or PostgreSQL setups.
Install via Composer:
composer require expresslanding/laravel-filesystem
Publish the config file (if needed) for custom disk configurations:
php artisan vendor:publish --provider="ExpressLanding\Filesystem\FilesystemServiceProvider" --tag="config"
First Use Case: Check if a disk exists or is present:
use ExpressLanding\Filesystem\Facades\Filesystem;
// Check if disk is present (connected, mounted, etc.)
$isPresent = Filesystem::disk('s3')->isPresent();
// Check if disk exists in configuration
$exists = Filesystem::disk('s3')->exists();
Disk Validation:
isPresent() to verify physical availability (e.g., network drives, cloud connections).exists() to validate configuration (e.g., disk is defined in filesystems.php).if (Filesystem::disk('custom')->isPresent() && Filesystem::disk('custom')->exists()) {
// Proceed with operations
}
Dynamic Disk Handling:
public function handle(Request $request, Closure $next)
{
if (!Filesystem::disk('s3')->isPresent()) {
abort(503, 'Storage unavailable');
}
return $next($request);
}
Fallback Logic:
Storage facade for hybrid checks:if (Filesystem::disk('local')->exists() && Storage::disk('local')->exists()) {
// Use Storage facade for operations
}
filesystems.php includes the driver key (fixed in v1.0.5). Example:
'disks' => [
's3' => [
'driver' => 's3', // Required for driver-type checks
'key' => env('AWS_KEY'),
// ...
],
],
$this->partialMock(Filesystem::class, 'isPresent')
->shouldReceive('isPresent')
->andReturnTrue();
check() method. Update calls from:
Filesystem::disk('s3')->check(); // ❌ Deprecated
to:
Filesystem::disk('s3')->isPresent(); // ✅ Physical check
Filesystem::disk('s3')->exists(); // ✅ Config check
isPresent() returns false unexpectedly, verify the driver key exists in filesystems.php. The v1.0.5 bug fix ensures this is required for accurate checks.isPresent() may return false for transient network issues. Implement retries or fallback disks:
$attempts = 0;
while (!$Filesystem::disk('s3')->isPresent() && $attempts < 3) {
sleep(2);
$attempts++;
}
Custom Drivers: Extend the package by creating a custom disk driver that implements isPresent() logic:
namespace App\Filesystem;
use ExpressLanding\Filesystem\Contracts\DiskInterface;
class CustomDisk implements DiskInterface {
public function isPresent(): bool {
// Custom logic (e.g., ping a service)
return true;
}
}
Register it in FilesystemServiceProvider:
$this->app->bind('custom', function () {
return new CustomDisk();
});
Event Listeners: Listen for disk state changes (e.g., when a disk becomes unavailable):
Filesystem::disk('s3')->listen(function ($disk) {
Log::warning("Disk {$disk->getName()} is no longer present");
});
How can I help you explore Laravel packages today?