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.php
will be publish inconfig
folder after that. - run
php artisan config:clear
to 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\MediaRemovable
Using The Model
- To use model method all you have to do is to add a private static parameter
mediaField
-
if you don't add
mediaField
automatically 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
mediaPath
like this -
If you have a complex structure to your media files in your application you can use the private method
mediaDetails
instead - 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
MediaRemovable
trait. -
And then set change your config file as you want
- The above code expect field
image
in all models usedMediaRemovable
trait, 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
details
instead. - Inside
details
array we use table name to track model details. - You can set multiple
tables
andfields
as 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
config
file information so if you set information to yourconfig
and yourmodel
, themodel
information will be overwrite byconfig
information 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.