leromo/laravel-filemanager

File Manager for Laravel

v1.0.0 2025-08-15 13:37 UTC

This package is auto-updated.

Last update: 2025-08-15 13:50:05 UTC


README

PHP Composer Latest Version on Packagist Total Downloads

Manage Files, Images, Docs with Eloquent models.

Getting Started

1. Install

Run the following command:

composer require leromo/laravel-filemanager

2. Publish

Publish config file.

php artisan vendor:publish --provider="Leromo\FileManager\FileManagerServiceProvider" --tag=filemanager-config

3. Preparing the database

You need to publish the migration to create the file table:

php artisan vendor:publish --provider="Leromo\FileManager\FileManagerServiceProvider" --tag=filemanager-migration

After that, you need to run migrations.

php artisan migrate

Usage

Your Eloquent models should use the Leromo\FileManager\Traits\HasFile trait.

Use blade component to add file uploader in your form.

<x-filemanager-file-upload name="image" />

For display old image in edit page.

<x-filemanager-file-upload name="image" :model="$model" />

Upload

$model = Model::find(1);
$model->handleFileFromRequest()->toFileCollection();

If your file input name is not image then define second param.

$model->handleFileFromRequest('banner')->toFileCollection();

Upload to specific collection.

$model->handleFileFromRequest()->toFileCollection('images');

You can define default collection at eloquent level. Add below function in your model.

public function defaultCollection(): string
{
    return 'promo_images';
}

Upload to specific disk.

$model->handleFileFromRequest()->useDisk('s3')->toFileCollection();

Register File Conversions

public function registerFileConversions()
{
    $this->addFileConversion('promo_image')
        ->width(420)
        ->height(350);
}

You can register as many file conversions as you want

public function registerFileConversions()
{
    $this->addFileConversion('promo_image')
        ->width(420)
        ->height(350);

    $this->addFileConversion('banner')
        ->width(700)
        ->height(550);
}

Default force crop is disabled, but you can enable it

$this->addFileConversion('promo_image')
    ->width(420)
    ->height(350)
    ->crop();

Disable Conversions

If you want to disable registered conversions on some files

$model->handleFileFromRequest()->withoutConversions()->toFileCollection();

Configuration

Define your layout stack in config file.

'stack' => 'footer',

Or you can use our blade directive.

@filemanagerScript

Gallery with Dropzone

<x-filemanager-dropzone name="gallery" />

Attach gallery to model using blelow code.

$model->attachGalleryToModelFromRequest('gallery')->toFileCollection();

You can also define collection for gallery.

<x-filemanager-dropzone name="gallery" collection="dropzone" />

You can define model to dropzone component as well. When you define model to component all images are automatically attached to model.

<x-filemanager-dropzone name="gallery" :model="$model" />

You can also change the default dropzone message.

<x-filemanager-dropzone name="gallery" message="Drop files here" />

Add File from Url

$model->addFileFromUrl($url, 'image')->toFileCollection();

Implements with Laravel Settings

Install settings package

composer require leromo/laravel-settings

Blade component to display old file

<x-filemanager-file-upload name="image" setting="{{ setting()->get('name') }}" />

To upload file

setting()->upload($request->toArray(), 'file_name');

By default we expect file name is your option name, but you can define your option name as well

setting()->upload($request->toArray(), 'file_name', 'option_name');

Get Uploaded File Url

setting()->getFile('name');

Changelog

Please see Releases for more information what has changed recently.

Contributing

Pull requests are more than welcome. You must follow the PSR coding standards.

Security

If you discover any security related issues, please email leromo.dev@gmail.com instead of using the issue tracker.

License

The MIT License (MIT). Please see LICENSE for more information.