null
|
|
||
|---|---|---|
| .github | ||
| config | ||
| cookbook | ||
| database/migrations | ||
| docker/php | ||
| src | ||
| tests | ||
| .editorconfig | ||
| .gitattributes | ||
| .gitignore | ||
| CHANGELOG.md | ||
| CODE_OF_CONDUCT.md | ||
| composer.json | ||
| configure.sh | ||
| CONTRIBUTING.md | ||
| docker-compose.yml | ||
| ecs.php | ||
| LICENSE.md | ||
| Makefile | ||
| phpstan.neon.dist | ||
| phpunit.xml.dist | ||
| README-SKELETON.md | ||
| README.md | ||
| rector.php | ||
| SECURITY.md | ||
| TASKS.md | ||
| testbench.yaml | ||
Archive
A simplified Laravel media storage package focused on storage and URL generation without image conversions.
Features
- Simple fluent API for adding media files
- Polymorphic relationships - attach media to any model
- Collection organization - group media into logical collections
- Custom path generators - full control over file organization
- Query builder scopes - convenient filtering methods
- Auto-cleanup - files deleted when models are removed
- Transaction safety - atomic operations for data integrity
- Anonymous media - orphan files without owners
- Curator interface - support for non-Eloquent owners
Requirements
Requires PHP 8.4+
Installation
composer require cline/archive
Publish the configuration and migration:
php artisan vendor:publish --tag=archive-config
php artisan vendor:publish --tag=archive-migrations
php artisan migrate
Quick Start
1. Add trait to your model
use Cline\Archive\Contracts\Curator;
use Cline\Archive\Models\Concerns\HasArchive;
class User extends Model implements Curator
{
use HasArchive;
}
2. Add media files
use Cline\Archive\Archive;
// Add to a model
$media = Archive::add($request->file('avatar'))
->toCurator($user)
->toCollection('avatars')
->store();
// Anonymous media (no curator)
$media = Archive::add($file)
->asAnonymous()
->store();
// Full featured
$media = Archive::add($file)
->toCurator($user)
->toCollection('documents')
->withName('Annual Report')
->withFileName('report-2024.pdf')
->toDisk('s3')
->withProperties(['year' => 2024])
->store();
3. Retrieve media
// Via relationship
$avatars = $user->media()->where('collection', 'avatars')->get();
$avatar = $user->media()->where('collection', 'avatars')->first();
// Query builder scopes
$images = Media::inCollection('avatars')
->ownedBy($user)
->ofType('image')
->get();
// Get URL
$url = $avatar->getUrl();
Documentation
See the cookbook directory for comprehensive guides:
Change log
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
Security
If you discover any security related issues, please use the GitHub security reporting form rather than the issue queue.
Credits
License
The MIT License. Please see License File for more information.