curly-deni / laravel-storage
Laravel file storage with polymorphic file records and customizable filesystem adapters.
Requires
- php: ^8.3
- illuminate/contracts: ^11.0||^12.0||^13.0
- illuminate/database: ^11.0||^12.0||^13.0
- illuminate/filesystem: ^11.0||^12.0||^13.0
- illuminate/support: ^11.0||^12.0||^13.0
- league/flysystem-aws-s3-v3: ^3.25
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.8
- orchestra/testbench: ^11.0.0||^10.0.0||^9.0.0
- pestphp/pest: ^4.0
- pestphp/pest-plugin-arch: ^4.0
- pestphp/pest-plugin-laravel: ^4.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
curly-deni/laravel-storage adds polymorphic file records and filesystem helpers
to Laravel applications. The package namespace is Aesis\Storage.
Installation
composer require curly-deni/laravel-storage
php artisan vendor:publish --tag="storage-migrations"
php artisan migrate
Publish the configuration when you need to change the defaults:
php artisan vendor:publish --tag="storage-config"
The storage.table option defaults to storage__files, preserving the table
name used by the application module. Set storage.public_disk to override the
default disk. When it is null, the package uses filesystems.public if your
application defines it, and otherwise uses public.
Store files
Files are associated with an Eloquent model through a nullable polymorphic
owner relation. The default storeContents method writes to the configured
public disk. Other methods allow selecting a disk or copying a stream/file from
another disk.
use Aesis\Storage\Models\File; $file = File::storeContents($user, 'avatars', $contents, 'png', 'image/png'); $url = $file->resolvedUrl(); $file->delete(); // Deletes the stored object and its database record.
Available storage methods are storeContents, storeContentsOnDisk,
storeStreamOnDisk, and storeFromDisk. An external filesystem value treats
the file path as an already resolved URL and skips filesystem deletion.
Filesystem adapter
The package registers the aesis_s3 filesystem driver. It retains the path
prefix from an S3 endpoint when building URLs, including path-style endpoints
used by S3-compatible services. Disks using the driver keep Laravel's regular
S3 options such as key, secret, region, bucket, url, endpoint, and
use_path_style_endpoint.
The source application adds two disk options consumed by the package's
accessUrl method:
url_accessselects URL generation.publiccalls the disk'surl()method; any other value generates a temporary URL.temporary_url_ttlsets the default temporary URL lifetime in minutes. It defaults to30when omitted and is used unless a caller passes an explicit expiration time.
The private S3 disk can also set Laravel's temporary_url option to replace
the base URL used for signed links. The custom S3 adapter preserves any path
prefix in that URL. This is useful when the S3 API endpoint and the URL exposed
to clients are different.
For example, the source app configures private files for expiring URLs and public files for stable URLs:
's3-private' => [ 'driver' => 'aesis_s3', // Laravel S3 credentials, bucket, endpoint, and path-style options... 'url_access' => 'temporary', 'temporary_url_ttl' => 30, ], 's3-public' => [ 'driver' => 'aesis_s3', // Laravel S3 credentials, bucket, endpoint, and path-style options... 'url_access' => 'public', ],
Testing and code style
composer test
composer analyse
composer format
License
MIT. See LICENSE.md.