patrikjak/utils
Composer 安装命令:
composer require patrikjak/utils
包简介
A simple utility package for Laravel
README 文档
README
The Utils package is a versatile utility toolkit designed to enhance Laravel applications. It provides a variety of reusable classes and functions to streamline development, including CSS and JavaScript assets to support frontend components like buttons, modals, and tables. Easily integrate the package into your project, publish assets, and selectively include only the styles and functions you need for a highly customizable setup. Perfect for Laravel developers seeking to simplify their workflow with ready-to-use utilities.
Table of Contents
What's included:
- CSS - A collection of reusable styles for buttons, modals, tables, and more.
- JavaScript - A variety of functions to enhance user experience and streamline development.
- Forms - A set of form components to simplify form creation.
- Tables - A collection of table components to enhance data presentation.
- Modals - A set of modal components to display content in a modal window.
- Notifications - A collection of notification components to display messages to users.
You can find the full documentation here.
Installation
Install the package via Composer:
composer require patrikjak/utils
Setup
After installing the package, add the package provider to the providers array in bootstrap/providers.php.
use Patrikjak\Utils\UtilsServiceProvider; return [ ... UtilsServiceProvider::class, ];
Next, publish the pre-built assets:
php artisan vendor:publish --tag="pjutils-assets" --force
This copies the compiled CSS and JS files to public/vendor/pjutils/. Re-run it with --force after every package update.
If you want to customize the SCSS or TypeScript source files, publish them separately:
php artisan vendor:publish --tag="pjutils-sources"
Usage
The Utils package offers a variety of useful classes and functions.
CSS
To include all component styles, add the main.css file:
<link rel="stylesheet" href="{{ asset('vendor/pjutils/assets/main.css') }}">
You need to set border-box box-sizing for all elements in your CSS file to prevent layout issues:
* { box-sizing: border-box; }
JavaScript
The package ships a pre-built ES module bundle. Include it as a <script> tag before your own scripts:
<script src="{{ asset('vendor/pjutils/assets/main.js') }}" defer type="module"></script>
type="module" is required. The bundle auto-initializes all components and exposes a window.pjutils global.
Auto-initialization
These components initialize automatically on page load — no manual calls needed: password visibility switch, table functions (pagination, sorting, filtering, search), dropdowns, file uploaders, accordions, tabs, clipboard, number inputs, comboboxes, tag inputs, repeaters.
Programmatic API
| Symbol | Type | Description |
|---|---|---|
Form |
class | AJAX form submission with validation error handling |
Modal |
class | Programmatic modal creation and control |
notify |
function | Show notification messages |
getData |
function | Read HTML data attributes from elements |
doAction |
function | Bind custom row actions on a table |
window.pjutils.notify('Saved', 'Success', 'success'); new window.pjutils.Form().bindSubmit(); const modal = new window.pjutils.Modal(); modal.setTitle('Hello').setBody('<p>Content</p>').open();
TypeScript
Add a declaration file at resources/js/pjutils.d.ts for full type safety — the import type imports are erased at build time, nothing from the vendor directory gets bundled:
import type Form from '../../vendor/patrikjak/utils/resources/assets/js/form/Form'; import type notify from '../../vendor/patrikjak/utils/resources/assets/js/utils/notification'; import type Modal from '../../vendor/patrikjak/utils/resources/assets/js/utils/Modal'; import type {getData} from '../../vendor/patrikjak/utils/resources/assets/js/helpers/general'; import type {doAction} from '../../vendor/patrikjak/utils/resources/assets/js/table/actions'; export {}; declare global { interface Window { pjutils: { Form: typeof Form; notify: typeof notify; Modal: typeof Modal; getData: typeof getData; doAction: typeof doAction; }; } }
Make sure resources/js is included in your tsconfig.json:
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "bundler",
"strict": true,
"noEmit": true,
"skipLibCheck": true
},
"include": [
"resources/js/**/*"
]
}
To load the correct language for JS components, set the lang attribute on the <html> tag:
<html lang="{{ config('app.locale') }}">
Currently supported languages: en, sk.
Your vite.config.js must target esnext:
export default defineConfig({ ... build: { target: 'esnext', }, });
patrikjak/utils 适用场景与选型建议
patrikjak/utils 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.09k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 10 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「utility」 「utils」 「laravel」 「tables」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 patrikjak/utils 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 patrikjak/utils 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 patrikjak/utils 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A set of useful PHP classes.
n2n test utils
A collection of enhancements and utilities for the Silverstripe UserForms module
Extends TYPO3 EXT:seo hreflang functionality
PHP7 utility classes
GHT D-Tools Bundle
统计信息
- 总下载量: 1.09k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-10-24