PHPackages                             au9500/laravel-blade-push-once-directive - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. au9500/laravel-blade-push-once-directive

ActiveLibrary[Templating &amp; Views](/categories/templating)

au9500/laravel-blade-push-once-directive
========================================

Blade @pushOnce directive for idempotent stack pushes in Laravel.

v1.0.0(4mo ago)045MITPHPPHP ^8.2

Since Jan 13Pushed 4mo agoCompare

[ Source](https://github.com/AU9500/laravel-blade-push-once-directive)[ Packagist](https://packagist.org/packages/au9500/laravel-blade-push-once-directive)[ RSS](/packages/au9500-laravel-blade-push-once-directive/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (4)Versions (3)Used By (0)

🚀 Laravel Blade PushOnce Directive
==================================

[](#-laravel-blade-pushonce-directive)

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
----------

[](#-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
--------------

[](#-installation)

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

Laravel automatically discovers the service provider.

---

🛠 Usage
-------

[](#-usage)

### 🔹 Basic Example

[](#-basic-example)

@pushOnce('scripts')

&lt;script src="/js/app.js"&gt;&lt;/script&gt; @endPushOnce

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

---

### 🔹 With a Custom Key

[](#-with-a-custom-key)

@pushOnce('styles', 'datepicker')

 @endPushOnce Ensures this block is pushed once per request.

---

### 🔹 In Partials

[](#-in-partials)

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

@pushOnce('scripts')

&lt;script&gt;console.log('loaded');&lt;/script&gt; @endPushOnce

Usage:

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

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

---

### 🔹 In Layouts

[](#-in-layouts)

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

---

🔍 How It Works
--------------

[](#-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
---------------

[](#-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 &amp; stacks

---

🛡 Requirements
--------------

[](#-requirements)

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

---

🤝 Contributing
--------------

[](#-contributing)

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

---

📄 License
---------

[](#-license)

MIT License.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance77

Regular maintenance activity

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

125d ago

Major Versions

v0.1.0 → v1.0.02026-01-13

### Community

Maintainers

![](https://www.gravatar.com/avatar/a15a63c46d239d42b8ed4c2fe9adbc5fe99eb62f6e5bb90f08021e0c068e8b37?d=identicon)[AU9500](/maintainers/AU9500)

---

Top Contributors

[![AU9500](https://avatars.githubusercontent.com/u/122030400?v=4)](https://github.com/AU9500 "AU9500 (3 commits)")

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/au9500-laravel-blade-push-once-directive/health.svg)

```
[![Health](https://phpackages.com/badges/au9500-laravel-blade-push-once-directive/health.svg)](https://phpackages.com/packages/au9500-laravel-blade-push-once-directive)
```

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M2.6k](/packages/craftcms-cms)[robsontenorio/mary

Gorgeous UI components for Livewire powered by daisyUI and Tailwind

1.5k454.7k15](/packages/robsontenorio-mary)[livewire/blaze

A tool for optimizing Blade component performance by folding them into parent templates

688221.3k17](/packages/livewire-blaze)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

44643.1k1](/packages/pressbooks-pressbooks)[rareloop/lumberjack-core

A powerful MVC framework for the modern WordPress developer. Write better, more expressive and easier to maintain code

42155.0k19](/packages/rareloop-lumberjack-core)[konekt/html

HTML and Form Builders for the Laravel Framework

24403.2k5](/packages/konekt-html)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
