odwini / laravel-mediable
A package for easily uploading and attaching media files to models with Laravel fork from plank/laravel-mediable
Requires
- php: >=7.2.0
- ext-fileinfo: *
- illuminate/database: ^5.6|^6.0|^7.0
- illuminate/filesystem: ^5.6|^6.0|^7.0
- illuminate/support: ^5.6|^6.0|^7.0
- league/flysystem: ~1.0.23
- psr/http-message: ^1.0
Requires (Dev)
- aws/aws-sdk-php: ~3.29.0
- guzzlehttp/guzzle: ^6.3
- guzzlehttp/promises: ^1.3
- league/flysystem-aws-s3-v3: ~1.0.23
- orchestra/testbench: ^3.3|^4.0|^5.0
- php-coveralls/php-coveralls: ^2.1
- phpunit/phpunit: ^8.0|^9.0
- vlucas/phpdotenv: ^3.3
This package is not auto-updated.
Last update: 2024-11-09 12:34:58 UTC
README
Laravel-Mediable is a package for easily uploading and attaching media files to models with Laravel 5.
Features
- Filesystem-driven approach is easily configurable to allow any number of upload directories with different accessibility.
- Many-to-many polymorphic relationships allow any number of media to be assigned to any number of other models without any need to modify the schema.
- Attach media to models with tags, to set and retrieve media for specific purposes, such as
'thumbnail'
,'featured image'
,'gallery'
or'download'
. - Easily query media and restrict uploads by MIME type, extension and/or aggregate type (e.g.
image
for jpeg, png or gif).
Example Usage
Upload a file to the server, and place it in a directory on the filesystem disk named "uploads". This will create a Media record that can be used to refer to the file.
$media = MediaUploader::fromSource($request->file('thumb'))
->toDestination('uploads', 'blog/thumbnails')
->upload();
Attach the Media to another eloquent model with one or more tags defining their relationship.
$post = Post::create($this->request->input());
$post->attachMedia($media, ['thumbnail']);
Retrieve the media from the model by its tag(s).
$post->getMedia('thumbnail')->first()->getUrl();
Installation
Add the package to your Laravel app using composer
composer require plank/laravel-mediable
Register the package's service provider in config/app.php
. In Laravel versions 5.5 and beyond, this step can be skipped if package auto-discovery is enabled.
'providers' => [
...
Plank\Mediable\MediableServiceProvider::class,
...
];
The package comes with a Facade for the image uploader, which you can optionally register as well. In Laravel versions 5.5 and beyond, this step can be skipped if package auto-discovery is enabled.
'aliases' => [
...
'MediaUploader' => Plank\Mediable\MediaUploaderFacade::class,
...
]
Publish the config file (config/mediable.php
) and migration file (database/migrations/####_##_##_######_create_mediable_tables.php
) of the package using artisan.
php artisan vendor:publish --provider="Plank\Mediable\MediableServiceProvider"
Run the migrations to add the required tables to your database.
php artisan migrate
Documentation
Read the documentation here.
License
This package is released under the MIT license (MIT).
About Plank
Plank is a web development agency based in Montreal, Canada.