承接 codeflextech/laravel-uploader 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

codeflextech/laravel-uploader

最新稳定版本:2.0.1

Composer 安装命令:

composer require codeflextech/laravel-uploader

包简介

Reusable Laravel uploader with DB tracking, polymorphic relations, S3 support & optimization

README 文档

README

A production-ready Laravel file uploader with:

  • Polymorphic relations
  • Public & private files
  • Local / S3 support
  • Image optimization
  • Auto cleanup on model delete
  • Multiple File Types Support

Installation

composer require codeflextech/laravel-uploader


## Configuration

Publish the config file to customize defaults:

```bash
php artisan vendor:publish --tag=uploader-config

Key Config Options (config/uploader.php)

  • table_name: The database table name (default: files). Can be set via UPLOAD_TABLE_NAME env var.
  • disk: Default storage disk (e.g., public, s3).
  • folder: Default folder name inside the disk (default: uploads).
  • structure: Date structure for organized files (default: year/month/week).
  • visibility: File visibility (public or private).
  • optimize_images: Auto-resize images (boolean).

Direct Public Uploads

By default, files are stored in storage/app/public and symlinked. If you want to upload directly to the public/ folder (bypassing storage/), you can define a custom disk.

  1. Add to config/filesystems.php:

    'public_uploads' => [
        'driver' => 'local',
        'root'   => public_path('uploads'), // Uploads to public/uploads
        'url'    => env('APP_URL').'/uploads',
        'visibility' => 'public',
    ],
  2. Use it in your upload:

    $user->upload($file, ['disk' => 'public_uploads']);

Basic Usage

1. Add Trait to Model

Add the HasFiles trait to any model that should have files attached (e.g., User, Post, Product).

use CodeFlexTech\Uploader\Traits\HasFiles;

class User extends Authenticatable
{
    use HasFiles;
}

2. Upload a File

Use the FileUploader facade or class to handle uploads.

$user->upload(
    $request->file('avatar'),
    [
        'folder' => 'avatars',
        'disk'   => 'public',
        'type'   => 'profile_pic'
    ]
);

Advanced Usage: File Types & Validation

You can categorize uploads by type (e.g., 'resume', 'profile_pic').

1. Upload with Type

Pass the type in the options array. If omitted, it defaults to 'file'.

$user->upload($file, ['type' => 'resume']);

2. Replacing Files

By default, the upload() method enforces a 1-to-1 relationship per type. If a user already has a 'profile_pic' and uploads a new one, the old file will automatically be deleted from storage and the database before the new one is saved.

3. Retrieve Files by Type

The HasFiles trait provides helper methods:

// Get all resumes
$resumes = $user->filesByType('resume')->get();

// Get the latest profile picture
$pic = $user->latestFile('profile_pic');

License

MIT

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-15

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固