plank / laravel-mediable
A package for easily uploading and attaching media files to models with Laravel
Installs: 1 117 460
Dependents: 19
Suggesters: 0
Security: 0
Stars: 767
Watchers: 20
Forks: 101
Open Issues: 12
Requires
- php: >=8.1.0
- ext-fileinfo: *
- guzzlehttp/guzzle: ^7.4.1
- guzzlehttp/psr7: ^2.6
- illuminate/database: ^10.0|^11.0
- illuminate/filesystem: ^10.0|^11.0
- illuminate/support: ^10.0|^11.0
- intervention/image: ^2.7.1|^3.0
- league/flysystem: ^3.0.4
- spatie/image-optimizer: ^1.7
- symfony/http-foundation: ^6.0.3|^7.0
- symfony/mime: ^6.0|^7.0
Requires (Dev)
- aws/aws-sdk-php: ^3.166.2
- doctrine/dbal: ^2.11|^3.0
- guzzlehttp/promises: ^1.5.1
- laravel/legacy-factories: ^1.3.0
- league/flysystem-aws-s3-v3: ^3.0
- mockery/mockery: ^1.4.2
- orchestra/testbench: ^8.0|^9.0
- php-coveralls/php-coveralls: ^2.5.2
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.0
- vlucas/phpdotenv: ^5.4.1
Suggests
- intervention/image-laravel: Laravel bindings for the intervention/image package used for image manipulation
- dev-master
- v6.x-dev
- 6.1.3
- 6.1.2
- 6.1.1
- 6.1.0
- 6.0.5
- 6.0.4
- 6.0.3
- 6.0.2
- 6.0.1
- 6.0.0
- 5.9.1
- 5.9.0
- 5.8.0
- 5.7.0
- 5.6.0
- 5.5.0
- 5.4.1
- 5.4.0
- 5.3.1
- 5.2.1
- 5.2.0
- 5.1.1
- 5.1.0
- 5.0.7
- 5.0.6
- 5.0.5
- 5.0.4
- 5.0.3
- 5.0.2
- 5.0.1
- 5.0.0
- 4.4.2
- 4.4.1
- 4.4.0
- 4.3.2
- 4.3.1
- 4.3.0
- 4.2.3
- 4.2.2
- 4.2.1
- 4.2.0
- 4.1.0
- 4.0.1
- 4.0.0
- 3.0.1
- 3.0.0
- 2.9.0
- 2.8.2
- 2.8.1
- 2.8.0
- 2.7.3
- 2.7.2
- 2.7.1
- 2.7.0
- 2.6.2
- 2.6.1
- 2.6.0
- 2.5.0
- 2.4.8
- 2.4.7
- 2.4.6
- 2.4.5
- 2.4.4
- 2.4.3
- 2.4.2
- 2.4.1
- 2.4.0
- 2.3.0
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.0
- 2.0.0
- 1.1.1
- 1.1.0
- 1.0.1
- 1.0.0
- 0.3.0
- 0.2.0
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- dev-uploaded-mime-type
- dev-laravel-9-temporary-url
- dev-support-8.1
- dev-update-changelog
- dev-source-adapter-url-path-parsing
- dev-callback-ordering
- dev-analysis-z4Db9N
- dev-develop
This package is auto-updated.
Last update: 2024-11-02 01:44:06 UTC
README
Laravel-Mediable is a package for easily uploading and attaching media files to models with Laravel.
Features
- Filesystem-driven approach is easily configurable to allow any number of upload directories with different accessibility. Easily restrict uploads by MIME type, extension and/or aggregate type (e.g.
image
for JPEG, PNG or GIF). - Many-to-many polymorphic relationships allow any number of media to be assigned to any number of other models without any need to modify their schema.
- Attach media to models with tags, in order to set and retrieve media for specific purposes, such as
'thumbnail'
,'featured image'
,'gallery'
or'download'
. - Integrated support for integration/image for manipulating image files to create variants for different use cases.
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
) 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.