PHPackages                             abdelhamiderrahmouni/blade-component-scopes - 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. abdelhamiderrahmouni/blade-component-scopes

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

abdelhamiderrahmouni/blade-component-scopes
===========================================

Scope attributes to specific elements within your Blade components.

v1.12.0(5mo ago)245MITPHPPHP ^8.2.0CI passing

Since Feb 19Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/abdelhamiderrahmouni/blade-component-scopes)[ Packagist](https://packagist.org/packages/abdelhamiderrahmouni/blade-component-scopes)[ GitHub Sponsors](https://github.com/abdelhamiderrahmouni)[ RSS](/packages/abdelhamiderrahmouni-blade-component-scopes/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (8)Versions (9)Used By (0)

 [![Blade Component Scopes](https://raw.githubusercontent.com/abdelhamiderrahmouni/blade-component-scopes/main/art/example.png)](https://raw.githubusercontent.com/abdelhamiderrahmouni/blade-component-scopes/main/art/example.png)

 [![GitHub Workflow Status (main)](https://camo.githubusercontent.com/cce000f9e9d11889c6098a65140fb1a56ef72a50a1064951b9502c9bc7e8b6bf/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f616264656c68616d696465727261686d6f756e692f626c6164652d636f6d706f6e656e742d73636f7065732f74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d726f756e642d737175617265)](https://github.com/abdelhamiderrahmouni/blade-component-scopes/actions) [![Total Downloads](https://camo.githubusercontent.com/7afcf888b9cbdc2810a9763a12342df06845acf93bcb4d9ce6df091eb96d4b82/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616264656c68616d696465727261686d6f756e692f626c6164652d636f6d706f6e656e742d73636f706573)](https://packagist.org/packages/abdelhamiderrahmouni/blade-component-scopes) [![Latest Version](https://camo.githubusercontent.com/7a0cc4c7386b5188ba04c89364b33eb9038de4390891cf5f887bcf7b4c55e074/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616264656c68616d696465727261686d6f756e692f626c6164652d636f6d706f6e656e742d73636f706573)](https://packagist.org/packages/abdelhamiderrahmouni/blade-component-scopes) [![License](https://camo.githubusercontent.com/4cb8bf4a718594d7f994d0b884cb7287be8478f28a3f189b4aff167302743ac6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f616264656c68616d696465727261686d6f756e692f626c6164652d636f6d706f6e656e742d73636f706573)](https://packagist.org/packages/abdelhamiderrahmouni/blade-component-scopes)

---

Blade Component Scopes
======================

[](#blade-component-scopes)

This package allows you to scope attributes to specific elements within your Blade components.

```
scope('label')->merge(['class' => 'text-gray-500']) }}>
```

Installation
------------

[](#installation)

> **Requires [php 8.2+](https://www.php.net/downloads.php) and [Laravel 10+](https://github.com/laravel/laravel)**

First, install `Blade Component Scopes` via [composer](https://getcomposer.org/):

```
composer require abdelhamiderrahmouni/blade-component-scopes
```

Usage
-----

[](#usage)

This package adds a `scope()` macro to Laravel's ComponentAttributeBag, allowing you to namespace your component attributes for different elements of your component.

### Basic Example

[](#basic-example)

```

```

In your component view, access scoped attributes using the scope() method:

```
// forms.input.blade.php
scope('container')->merge(['class' => 'flex gap-y-2']) }}>

    @if($label)
        scope('label')->merge(['class' => 'text-gray-500']) }}>
            {{ $label }}

    @endif

    scope('input')->merge(['class' => 'border-b']) }} />

```

### How It Works

[](#how-it-works)

The `scope()` method filters attributes based on the prefix. For example:

- The label's class in `label:class="font-bold"` becomes available when using `$attributes->scope('label')`
- The input's ID in `input:id="first-name-input"` becomes available when using `$attributes->scope('input')`
- The container's class in `container:class="mt-4"` becomes available when using `$attributes->scope('container')`

This allows you to:

1. Organize attributes for different elements/parts of your component
2. Create more intuitive component interfaces
3. Maintain cleaner component templates

### Benefits

[](#benefits)

- 🎯 Better organization of component attributes
- 🔍 More explicit attribute targeting
- 🧩 Cleaner components with less clutter
- 💪 Fully compatible with Laravel's existing attribute merging

> If you want to benifit from the `scope` method in your Blade views without installing this package, here is the magic sauce:

Add the following code to your `AppServiceProvider`:

```
// AppServiceProvider.php
use Illuminate\View\ComponentAttributeBag;

public function register(): void
{
    ComponentAttributeBag::macro('scope', function (string $scope): ComponentAttributeBag {
        $prefix = $scope . ':';
        $prefixLength = strlen($prefix);

        $scopedAttributes = [];
        foreach ($this->getAttributes() as $key => $value) {
            if (str_starts_with($key, $prefix)) {
                $scopedAttributes[substr($key, $prefixLength)] = $value;
            }
        }

        return new ComponentAttributeBag($scopedAttributes);
    });
}
```

Contributing
------------

[](#contributing)

Thank you for considering contributing to `Blade Component Scopes`! The contribution guide can be found in the [CONTRIBUTING.md](CONTRIBUTING.md) file.

---

`Blade Component Scopes` is an open-sourced software licensed under the **[MIT license](https://opensource.org/licenses/MIT)**.

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance71

Regular maintenance activity

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

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 ~40 days

Recently: every ~0 days

Total

8

Last Release

162d ago

Major Versions

v0.2.0 → v1.0.02025-11-29

v1.0.0 → 10.x-dev2025-12-01

v1.11.0 → 11.x-dev2025-12-01

### Community

Maintainers

![](https://www.gravatar.com/avatar/745a0575996f5a3dcb6b8e177e5f37e610d83906028a1e99aa2ec3213a281027?d=identicon)[abdelhamiderrahmouni](/maintainers/abdelhamiderrahmouni)

---

Top Contributors

[![abdelhamiderrahmouni](https://avatars.githubusercontent.com/u/26693672?v=4)](https://github.com/abdelhamiderrahmouni "abdelhamiderrahmouni (13 commits)")

---

Tags

bladeblade-componentslaravelphplaravelmergeclassestailwindcss

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/abdelhamiderrahmouni-blade-component-scopes/health.svg)

```
[![Health](https://phpackages.com/badges/abdelhamiderrahmouni-blade-component-scopes/health.svg)](https://phpackages.com/packages/abdelhamiderrahmouni-blade-component-scopes)
```

###  Alternatives

[gehrisandro/tailwind-merge-laravel

TailwindMerge for Laravel merges multiple Tailwind CSS classes by automatically resolving conflicts between them

341682.2k18](/packages/gehrisandro-tailwind-merge-laravel)[gehrisandro/tailwind-merge-php

TailwindMerge for PHP merges multiple Tailwind CSS classes by automatically resolving conflicts between them

1391.5M9](/packages/gehrisandro-tailwind-merge-php)[yieldstudio/tailwind-merge-php

Merge Tailwind CSS classes without style conflicts

4972.8k1](/packages/yieldstudio-tailwind-merge-php)

PHPackages © 2026

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