Download the PHP package roui/model-file-manager without Composer
On this page you can find all versions of the php package roui/model-file-manager. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package model-file-manager
Model File Manager Package
Introduction
The ModelFileManager package is a Laravel package designed to handle file storage at the model level. It provides features for uploading, deleting, and resizing files. Additionally, it supports multiple file collections and allows you to easily store and manage files such as images, documents, and more.
Requirements
- PHP: 8.3 or higher
- Laravel: 8.x or higher
- Intervention Image: 2.x
Installation
-
Install the package via Composer:
-
Publish the configuration file:
- Ensure the
Intervention Image
package is installed:
Configuration
After publishing the configuration, you will find the config file at config/modelfilemanager.php
. You can customize the following settings:
- storage_disk: The default storage disk to use.
- resized_image_path: The path for storing resized images.
- default_collection: The default collection name for file uploads.
Example of config/modelfilemanager.php
:
Usage
-
Upload a File: You can upload a file to a model by using the
uploadFile()
method. Specify the file, collection, and disk if needed. -
Delete a File: To delete a file from a specific collection, use the
deleteFile()
method: -
Get Files: Retrieve all files from a model’s files column:
-
Get Files from a Collection: Get files from a specific collection, with optional resizing:
-
Replace a File: You can replace an old file with a new one in a collection:
-
Get Resized Image: Get a resized version of a file by specifying dimensions:
- Automatically Cast Files as Array: The files attribute is automatically cast as an array when accessing it:
Methods Overview
- uploadFile($file, $collection = null, $disk = null): Upload a file to a collection and disk.
- deleteFile($filePath, $collection = null, $disk = null): Delete a file from a collection and disk.
- getFiles(): Get all files from the model.
- getFilesFromCollection($collection = null, $width = null, $height = null, $disk = null): Get files from a collection with optional resizing.
- replaceFileInCollection($newFile, $collection = null, $disk = null): Replace an old file with a new one in a collection.
- getResizedImage($filePath, $width, $height, $disk = null): Get a resized version of an image.
- getFirstFileFromCollection($collection = null, $width = null, $height = null, $disk = null): Get the first file from a collection.
- getFilesAttribute($value): Automatically cast the 'files' column to an array.
License
This package is open-sourced software licensed under the MIT license.