alboradait/laravel-progress 问题修复 & 功能扩展

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

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

alboradait/laravel-progress

Composer 安装命令:

composer require alboradait/laravel-progress

包简介

Progress tracking tools for Laravel

README 文档

README

This package allows you to easily track user progress through any kind of progressable resource: courses, tutorials, onboarding flows, or any custom process with defined steps.

Features

  • Easily track progress for Eloquent models implementing Progressable
  • Built-in trait TracksProgress with sensible defaults
  • Progress-related events:
    • ProgressStarted
    • ProgressUpdated
    • ProgressCompleted
    • ProgressAbandoned
    • ProgressRestarted
  • Automatic recalculation on demand
  • Weighted step support
  • Blade components for displaying progress
  • Configuration-driven
  • Test-covered and queue-ready
  • In development: Progress Reports

Installation

composer require alboradait/laravel-progress

If you're using Laravel 11+, package auto-discovery is enabled.

To publish the config file:

php artisan vendor:publish --tag=progress-config

To publish views (Blade components):

php artisan vendor:publish --tag=progress-views

Usage

1. Implement the Progressable Interface

use AlboradaIT\LaravelProgress\Contracts\Progressable;
use AlboradaIT\LaravelProgress\Support\Traits\TracksProgress;

class Course extends Model implements Progressable
{
    use TracksProgress;

    // Define the steps of a progress
    public function definedSteps(): array
    {
        return $this->learningUnits;
    }

    public function getCompletedSteps(User $user): array
    {
        return $user->completedLearningUnits;
    }
}

2. Update Progress

$course->updateUserProgress($user);

This will update the ProgressRecord, and dispatch events if something changed.

3. Reset Progress

$course->resetProgress($user);

🔔 Note: Resetting the progress record only affects the internal ProgressRecord (percentage, status, etc). It does not remove any external state like completedLearningUnits — you're responsible for clearing that if needed.

4. Listen to Events

All progress events are dispatched via Laravel's event system, so you can listen to them using listeners, jobs, or observers.

Events

Event Description
ProgressStarted Fired when a new progress starts
ProgressUpdated Fired when percentage changes
ProgressCompleted Fired when 100% progress is reached
ProgressAbandoned Fired when no progress after a time threshold
ProgressRestarted Fired when progress is manually reset

Configuration

After publishing the config file, you'll find config/progress.php:

return [
    'queue_connection' => env('PROGRESS_QUEUE_CONNECTION', 'sync'),
    'queue_name' => env('PROGRESS_QUEUE', 'default'),
    'abandon_after' => 3600 * 24 * 30, // 30 days (in seconds)
];

Advanced Features

Weighted Steps

Define steps with metadata (e.g., duration):

public function definedSteps(): array {
    return [
        ['name' => 'intro', 'duration' => 300],
        ['name' => 'chapter_1', 'duration' => 1200],
        ['name' => 'chapter_2', 'duration' => 600],
    ];
}

public function getWeightForStep(mixed $step): int {
    return $step['duration'] ?? 1;
}

Recalculating Progresses

Trigger mass recalculations by dispatching events that implement the ShouldTriggerProgressRecalculation interface:

use AlboradaIT\LaravelProgress\Contracts\ShouldTriggerProgressRecalculation;

class LearningUnitDeleted implements ShouldTriggerProgressRecalculation
{
    public function __construct(public Course $course) {}

    public function getProgressables(): array
    {
        return [$this->course];
    }
}

📝 You can return multiple progressables from getProgressables(). All of them will be recalculated.

Queue Behavior

  • updateUserProgress($user) runs immediately. It's designed for real-time UI updates or per-user actions.
  • Events triggered by implementing ShouldTriggerProgressRecalculation are queued and processed asynchronously. This allows recalculating hundreds or thousands of progresses efficiently.

To change the queue connection or name, edit config/progress.php.

If you use queue_connection = sync, listeners will be run immediately.

Blade Components

This package includes a couple of Blade components:

<x-laravel-progress::progress-bar :progress="$record" />
<x-laravel-progress::circular-progress :progress="$record" />

You can publish and customize the views:

php artisan vendor:publish --tag=progress-views

Testing

This package is covered with a comprehensive test suite. To run tests:

vendor/bin/phpunit

Uses Orchestra Testbench for package testing.

License

MIT License. Copyright (c) Alborada IT.

alboradait/laravel-progress 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-24