Download the PHP package codebuglab/laravel-media-removable without Composer
On this page you can find all versions of the php package codebuglab/laravel-media-removable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download codebuglab/laravel-media-removable
More information about codebuglab/laravel-media-removable
Files in codebuglab/laravel-media-removable
Package laravel-media-removable
Short Description Automatically remove media like images, videos, and audios from storage folder once record with media deleted or updated from database
License MIT
Informations about the package laravel-media-removable
⚡⚡⚡ Laravel Media Removable
Automatically remove media like images, videos, and audios from storage folder once record with media deleted or updated from database
Table of contents
- Setup
- Installation
- Publish
- Instructions
- Using The Model
- Using Config File
- Important Notice
- Testing
- License
Setup
Installation
To install this package through composer run the following command in the terminal
Publish
You have to publish config file with this artisan command:
- File
media-removable.phpwill be publish inconfigfolder after that. - run
php artisan config:clearto update application with published file.
Instructions
Here is multiple ways to use this package to delete media files from your project during updating and deleting database row using eloquent.
- You have to use the trait
CodeBugLab\MediaRemovable\MediaRemovableUsing The Model
- To use model method all you have to do is to add a private static parameter
mediaField -
if you don't add
mediaFieldautomatically the package will throw and exception. - by using the method the package will determine files path from config file which already set at
config\media_removable.php -
if you want to change file path for all the project you can change it from config file or use the private method
mediaPathlike this -
If you have a complex structure to your media files in your application you can use the private method
mediaDetailsinstead - Here you can determine every column folder path individually.
Using Config File
- Alternatively you can use the config file to set all your media details instead of the model.
-
keep using
MediaRemovabletrait. -
And then set change your config file as you want
- The above code expect field
imagein all models usedMediaRemovabletrait, We don't think it's a practical way but we keep it if someone need it. -
If you have more details than that you can use
detailsinstead. - Inside
detailsarray we use table name to track model details. - You can set multiple
tablesandfieldsas you can see, this way will make the model much cleaner specially if you have multiple fields.
Important Notice
- The priority in this package is for
configfile information so if you set information to yourconfigand yourmodel, themodelinformation will be overwrite byconfiginformation so be carful with that.
Testing
To run test use this command vendor/bin/phpunit
License
This package is a free software distributed under the terms of the MIT license.