pakpromo/laravel-filemanager 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pakpromo/laravel-filemanager

最新稳定版本:v1.0.0

Composer 安装命令:

composer require pakpromo/laravel-filemanager

包简介

File Manager for Laravel

README 文档

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 pakpromo/laravel-filemanager

2. Publish

Publish config file.

php artisan vendor:publish --provider="PakPromo\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="PakPromo\FileManager\FileManagerServiceProvider" --tag=filemanager-migration

After that, you need to run migrations.

php artisan migrate

Usage

Your Eloquent models should use the PakPromo\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 pakpromo/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 snippetcms@gmail.com instead of using the issue tracker.

License

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

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-08