drands/laravel-utils
Composer 安装命令:
composer require drands/laravel-utils
包简介
A collection of Laravel utilities created by De Ramos & Serch.
README 文档
README
Installation
composer require drands/laravel-utils
Utils
DeleteOnCascade Trait
This trait can be used to automatically delete related models when a parent model is deleted. It leverages Laravel's model events to listen for deletions and cascade the delete operation to related models.
Usage
To use this trait, you need to include it in your Eloquent model:
use Drands\LaravelUtils\Traits\DeleteOnCascade; class Post extends Model { use DeleteOnCascade; protected $deleteOnCascade = ['mediaItems']; }
HasBuilder Trait
This trait provides functionality to manage media files associated with a model that uses a builder pattern. It ensures that media files are properly deleted when the model is deleted.
Usage
To use this trait, you need to include it in your Eloquent model:
use Drands\LaravelUtils\Traits\HasBuilder; class Post extends Model { use HasBuilder; protected $builders = ['body']; }
HasUploads Trait
This trait provides functionality to manage file uploads associated with a model. It ensures that uploaded files are properly deleted when the model is deleted.
Usage
To use this trait, you need to include it in your Eloquent model:
use Drands\LaravelUtils\Traits\HasUploads; class Post extends Model { use HasUploads; protected $uploadFields = ['file']; }
CloneTranslations (Filament Action)
This utility provides a Filament action to clone translations from one language to another. It allows you to select the source language, target languages, and specific fields to clone.
Usage
To use this utility, you need to include the action in your Filament resource:
use Drands\LaravelUtils\Filament\Actions\CloneTranslations; public static function getActions(): array { return [ CloneTranslations::make() ->builderFields(['body']), // Specify the builder fields ]; }
Helpers
getFileExtension($filePath)
This helper function retrieves the file extension from a given file path.
isValidFileExtension($filePath, Array $validExtensions)
This helper function checks if the file extension of the given file path is valid based on the provided list of valid extensions.
isImageFile($filePath)
This helper function checks if the given file path is an image file based on its extension.
isVideoFile($filePath)
This helper function checks if the given file path is a video file based on its extension.
getCurrentGitCommitHash()
This helper function retrieves the current Git commit hash of the project.
media_embed($id, $host, $attributes = [], $params = [])
This helper function generates an HTML embed code for a media file.
money_format($number, $showZeros = true, $decimals = 2, $showCurrency = true)
This helper function formats a number as a monetary value.
setting($key, $default = null)
This helper function retrieves the value of a specific setting.
uploadFileNamer(TemporaryUploadedFile $file, $disk = 'public')
This helper function generates a unique name for an uploaded file.
pageShow($slug = '')
Route::get('/about', pageShow('about'))->name('about');
This helper function allows you to create a route for the "show" page of a given resource.
pageIndex($slug = '')
Route::get('/about', pageIndex('about'))->name('about');
This helper function allows you to create a route for the "index" page of a given resource.
imageUrl($filename = '')
This helper function generates a URL for a given image file if it exists, otherwise it returns a default placeholder image URL.
drands/laravel-utils 适用场景与选型建议
drands/laravel-utils 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 164 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 04 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 drands/laravel-utils 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 drands/laravel-utils 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 164
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-18