au9500/laravel-blade-push-once-directive 问题修复 & 功能扩展

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

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

au9500/laravel-blade-push-once-directive

Composer 安装命令:

composer require au9500/laravel-blade-push-once-directive

包简介

Blade @pushOnce directive for idempotent stack pushes in Laravel.

README 文档

README

A lightweight Laravel Blade extension that adds an idempotent @pushOnce directive. This ensures Blade stack content is pushed only once, even if the directive appears multiple times or inside repeatedly included partials or components.

Prevent duplicate JavaScript, CSS, or inline script blocks effortlessly. ✨

✨ Features

  • 🧩 Idempotent Blade @pushOnce directive
  • 🔑 Optional unique key support
  • ⚙️ Auto-generated key (based on file + line) if none provided
  • 🔁 Works in partials, components, includes, and layouts
  • 🚫 Prevents duplicate pushes completely
  • 🪶 Zero output buffering, fully Blade-native
  • 🧪 Fully tested with PHPUnit + Testbench
  • 📦 Minimal and clean implementation

📦 Installation

composer require au9500/laravel-blade-push-once-directive

Laravel automatically discovers the service provider.

🛠 Usage

🔹 Basic Example

@pushOnce('scripts')

<script src="/js/app.js"></script>

@endPushOnce

Even if included many times, this script is pushed only once into the scripts stack.

🔹 With a Custom Key

@pushOnce('styles', 'datepicker')

@endPushOnce

Ensures this block is pushed once per request.

🔹 In Partials

resources/views/partials/scripts.blade.php:

@pushOnce('scripts')

<script>console.log('loaded');</script>

@endPushOnce

Usage:

@include('partials.scripts')
@include('partials.scripts')
@include('partials.scripts')

Only one script block will appear in the final output. ✔️

🔹 In Layouts

@stack('scripts')

Any @pushOnce('scripts') from child views will be injected here — exactly once.

🔍 How It Works

The directive checks an internal registry:

  • If the stack/key combo has not been used yet → the content is pushed normally.
  • If it has been used → the entire block is skipped.

No output buffering, no duplicated content, fully compatible with Blade’s native stack behavior. 🧠

🧪 Running Tests

vendor/bin/phpunit

Included tests:

  • Same key twice → only one push
  • Different keys → all pushed
  • Partials included multiple times → only one push
  • Auto-generated default key behavior
  • Full HTML rendering through layouts & stacks

🛡 Requirements

  • PHP 8.2+
  • Laravel 10.x / 11.x / 12.x

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Commit your changes
  4. Open a pull request

📄 License

MIT License.

au9500/laravel-blade-push-once-directive 适用场景与选型建议

au9500/laravel-blade-push-once-directive 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 45 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 au9500/laravel-blade-push-once-directive 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-13