alifahmmed/helpers-package
Composer 安装命令:
composer require alifahmmed/helpers-package
包简介
A Laravel helper package for file uploads, slug generation, and JSON responses
README 文档
README
A versatile Laravel helper package providing utilities for file uploads, slug generation, JSON responses, database export, unit conversion, and more. Designed to speed up development by providing ready-to-use helpers and traits.
Table of Contents
Compatibility
This package is compatible with modern versions of Laravel and PHP:
Laravel: 9.x, 10.x, 11.x, and 12.x
PHP: 8.1 or higher
It leverages the latest features of PHP 8, including union types and improved type safety, and is fully compatible with Laravel’s service container, facades, and Eloquent ORM.
Features
- File and image upload/delete in public or storage.
- Generate unique slugs for models.
- JSON responses for success, error, and paginated data.
- Export the full database with SQL file download.
- Apply filters and pagination to queries easily.
- Convert file paths to full URLs for API responses.
- Change model status or delete records with Livewire.
- Unit conversions: cm ↔ feet, kg ↔ lbs.
- Helper methods for testing and general utilities.
Installation
Install via Composer:
composer require alifahmmed/helpers-package:^1.1.1
Configuration
The package auto-registers the service provider and facade:
'providers' => [ AlifAhmmed\HelperPackage\HelperServiceProvider::class, ], 'aliases' => [ 'Helper' => AlifAhmmed\HelperPackage\Helpers\Helper::class, ],
Usage
Helper Class
You can use the helper class directly for common tasks:
use AlifAhmmed\HelperPackage\Helpers\Helper; // File upload $path = Helper::fileUpload($request->file('image'), 'posts', 'My Post Image'); // File delete Helper::fileDelete('uploads/posts/my-post-image.jpg'); // Generate unique slug $slug = Helper::makeSlug(Post::class, 'My Post Title'); // JSON response return Helper::jsonResponse(true, 'Data fetched successfully', 200, $data); // JSON error response return Helper::jsonErrorResponse('Something went wrong', 400, ['field' => 'error']);
AllTraits
You can use AllTraits to include all package traits in any class:
use AlifAhmmed\HelperPackage\Traits\AllTraits; class PostController extends Controller { use AllTraits; }
ApiResponse
public function index() { $posts = Post::all(); return $this->success('Posts fetched successfully', $posts); } public function show($id) { $post = Post::find($id); if (!$post) { return $this->error('Post not found', 404); } return $this->ok('Post fetched successfully', $post); } public function listWithPagination() { $posts = Post::paginate(10); return $this->pagination('Posts list', $posts); } public function customPaginationExample() { $posts = Post::paginate(5); return $this->successPagination(true, 'Data fetched', 200, $posts, true); }
DatabaseExportable
public function export() { return $this->exportDatabase(); }
FileManager
// Upload files to public folder public function uploadFiles(Request $request) { $paths = $this->uploadToPublic($request->file('images'), 'posts'); return response()->json($paths); } // Delete files from public folder and update DB public function deleteFiles(Post $post) { $this->deleteFromPublic($post, 'images'); } // Upload files to storage folder public function uploadToStorageExample(Request $request) { $paths = $this->uploadToStorage($request->file('documents'), 'docs'); return response()->json($paths); } // Update files in public folder (delete old + upload new) public function updateFiles(Post $post, Request $request) { $paths = $this->updateToPublic($post, 'images', $request->file('images'), 'posts'); return response()->json($paths); }
HasFilter
public function index(Request $request) { $query = Post::query(); $query = $this->applyFilters($query, $request); $limit = $this->getLimit($request, 10); $posts = $query->paginate($limit); return response()->json($posts); }
ImagePathTrait
public function show(Post $post) { $post->image_url = $this->fullImageUrl($post->image); return response()->json($post); } // Only convert for API routes public function showApi(Post $post) { $post->image_url = $this->fullImageUrlForApi($post->image); return response()->json($post); }
SlugGenerator
$slug = $this->generateSlug(Post::class, 'slug', $request->title);
TestPerpose
return $this->testPerpose();
Unit Conversion
$this->cmToFeet(180); // 5.9055 $this->feetToCm(5.9); // 179.83 $this->kgToLbs(70); // 154.32 $this->lbsToKg(154); // 69.85
License
MIT License © S M Alif Ahmmed
Contribution
Feel free to contribute by submitting issues or pull requests on GitHub.
alifahmmed/helpers-package 适用场景与选型建议
alifahmmed/helpers-package 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 64 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 03 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「package」 「helper」 「laravel」 「file upload」 「JSON responses」 「slug generation」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 alifahmmed/helpers-package 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 alifahmmed/helpers-package 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 alifahmmed/helpers-package 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Datetime helpers for timezone handling
Library with classes to help you do batch.
This adds functions about array. If you feel like there few php built-in functions about array, this will be useful.
HTML and form generation
Simple ASCII output of array data
统计信息
- 总下载量: 64
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-30