sextanet/laravel-files 问题修复 & 功能扩展

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

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

sextanet/laravel-files

Composer 安装命令:

composer require sextanet/laravel-files

包简介

Connect real files with your models in Laravel 11+

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Upload seamless Storage and Database files in Laravel

It supports:

Requirements

  • Laravel 11+
  • PHP 8.3+

Installation

composer require sextanet/laravel-files

Publish and run the migrations with:

php artisan vendor:publish --tag="files-migrations"
php artisan migrate

Usage

use SextaNet\LaravelFiles\HasFiles; // 👈 1. Import

class YourModel extends Model
{
    use HasFiles; // 👈 2. Use it
}

We're ready! You can reuse it in each model, any times!

Add (and Store)

$uploaded_file = request()->your_file; // let's supose you have "a_video.mp4"

$file = $user->addFile($uploaded_file); // using your default disk from config/filesystems.php

Passing a destination and name

$file = $user->addFile($uploaded_file, 'destination', 'my_file'); // will store on destination/my_file.mp4

Get

You can get the path, url and temporary_url for each file

$path = $file->path();

$url = $file->url();

$temporary_url = $file->temporaryUrl();

Get owner

return $file->owner;

Get all files

return $user->files;

Get the latest file

return $user->latestFile;

Download

Without parameters

return $file->download();

With custom parameters

$name = 'custom_name';
$headers = [];

return $file->download($name, $headers);

Turn off the extensions

By default it preserves the extension. You can disable that by passing preserveExtension to false

return $file->download(preserveExtension: false);

Preserve original names

By default, it doesn't preserves original empty custom names.

Caution

If you enable that, you could overwrite your existent files.

LaravelFiles::preserveOriginalNames(true);

Advanced usage

Passing a type

Type doesn't represent a real type or mimetype, it's only an optional field

$uploaded_file = request()->your_file;

// Store
$user->addFile($uploaded_file, type: 'document');

// Get
$user->files()->type('document')->get();

Passing custom minutes in each implementation

$temporary_url = $file->getTemporaryUrl(20); // 20 minutes

Global usage

Passing custom minutes globally

// Don't forget to import the LaravelFiles facade
use SextaNet\LaravelFiles\Facades\LaravelFiles;

// Set temporary URL for 120 minutes
LaravelFiles::setTemporaryUrlMinutes(120);

$temporary_url = $file->getTemporaryUrl(); // Will return 120 minutes

Passing a different disk in a specific instance

// Don't forget to import the LaravelFiles facade
use SextaNet\LaravelFiles\Facades\LaravelFiles;

// Store on another disk, like s3
LaravelFiles::setDisk('s3');

Custom keys

By default, we use the same CURRENT_DISK that you have in your .env file. If you want to force to use different values, you can add these keys with different values:

Another disk

FILES_DISK=s3

Custom minutes

FILES_TEMPORARY_URL_MINUTES=5

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

License

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

sextanet/laravel-files 适用场景与选型建议

sextanet/laravel-files 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.79k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 09 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「files」 「laravel」 「eloquent」 「laravel-files」 「SextaNet」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 sextanet/laravel-files 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 sextanet/laravel-files 我们能提供哪些服务?
定制开发 / 二次开发

基于 sextanet/laravel-files 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-09-28