PHPackages                             eduardoribeirodev/laravel-scoped-slots - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. eduardoribeirodev/laravel-scoped-slots

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

eduardoribeirodev/laravel-scoped-slots
======================================

This is my package laravel-scoped-slots

v1.0.1(1mo ago)012MITPHP ^8.4

Since Jul 6Compare

[ Source](https://github.com/eduardoribeirodev/laravel-scoped-slots)[ Packagist](https://packagist.org/packages/eduardoribeirodev/laravel-scoped-slots)[ Docs](https://github.com//laravel-scoped-slots)[ RSS](/packages/eduardoribeirodev-laravel-scoped-slots/feed)WikiDiscussions Synced 1w ago

READMEChangelog (1)Dependencies (28)Versions (3)Used By (0)

Laravel Scoped Slots
====================

[](#laravel-scoped-slots)

[![Latest Version on Packagist](https://camo.githubusercontent.com/3a0c1a80118ca8d839d2b582a3f442c610d382087e712fc5799a460372fc1fc8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6564756172646f7269626569726f6465762f6c61726176656c2d73636f7065642d736c6f74732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/eduardoribeirodev/laravel-scoped-slots)[![License](https://camo.githubusercontent.com/3ff4f5516a5817df9c59b839b08ad9014fefaa980b5e6ec363835fd5e4e1fde4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6564756172646f7269626569726f6465762f6c61726176656c2d73636f7065642d736c6f74732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/eduardoribeirodev/laravel-scoped-slots)

**Laravel Scoped Slots** is a powerful Blade extension that brings scoped slots functionality to Laravel, inspired by modern frontend frameworks like Vue.js and Svelte.

It allows child components to expose data back to the parent's slot content using an elegant `let` syntax, while seamlessly preserving the parent view's variable scope.

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

[](#installation)

You can install the package via composer:

```
composer require eduardoribeirodev/laravel-scoped-slots
```

The package will automatically register its service provider. If you have package discovery disabled, you can manually register `EduardoRibeiroDev\LaravelScopedSlots\LaravelScopedSlotsServiceProvider` in your `bootstrap/providers.php`.

Why Scoped Slots?
-----------------

[](#why-scoped-slots)

In standard Laravel Blade, slots are static HTML strings. If you build a highly reusable component (like a list, a table, or a dropdown), the child component controls the loop or the logic, making it difficult to format each item from the parent view.

With **Scoped Slots**, the child component provides the data, but the parent view defines *how* it should be rendered.

Usage
-----

[](#usage)

Scoped slots are ideal when the child component owns the iteration or the data-loading logic, but the parent view should decide how each item is rendered. The component exposes values to the slot, and the parent receives them through the `let` attribute.

### Basic Example

[](#basic-example)

Let's say you have a `List` component that iterates over an array, but you want the parent view to dictate how each list item looks.

**1. Using the Component (Parent View):**You can use the `let` attribute to capture the variable exposed by the component.

```

        {{ $user->name }}
        {{ $user->email }}

```

**2. Defining the Component (`resources/views/components/list.blade.php`):**Inside the component, the `$slot` becomes a callable function. You can invoke it and pass the data.

```

    @foreach($items as $item)

        {{ $slot($item) }}
    @endforeach

```

Now, let's say you want to pass multiple variables back to the parent. You can do that too! A carousel is a great example of where scoped slots shine. The child component can manage the list of slides, while the parent decides the exact markup for each card or panel.

**Parent View:**

```

        #{{ $index + 1 }}
        {{ $slide['title'] }}
        {{ $slide['description'] }}

```

**Child Component (`resources/views/components/carousel.blade.php`):**

```

        @foreach($items as $index => $item)
            {{ $slot(
                item: $item,
                index: $index
            ) }}
        @endforeach

```

This pattern is especially useful when you want to keep the component reusable while still allowing each page or view to define its own presentation. Named arguments such as `item:` and `index:` make the slot invocation more explicit and easier to read, especially when several values are passed at once.

### Multiple Parameters

[](#multiple-parameters)

You can pass multiple variables back to the parent (for example, an item and its index).

**Parent View:**

```

    #{{ $index }} - {{ $user->name }}

```

**Child Component:**

```

    @foreach($items as $index => $item)
        {{ $slot($item, $index) }}
    @endforeach

```

### Supported Syntax Styles

[](#supported-syntax-styles)

The package provides developers with syntactic sugar that adapts to your coding style. The `$` symbol in the parameter name is optional; the package will inject it automatically if omitted.

All of the following syntaxes are perfectly valid and behave exactly the same:

**Vue.js Style (String):**

```

```

**Svelte Style (Colon):**

```

```

**With Explicit Variable Symbols (`$`):**

```

```

### Named Scoped Slots

[](#named-scoped-slots)

Scoped slots are not restricted to the default `$slot`. You can use them on named slots using Laravel's `` syntax, which is useful when a component needs to expose different templates for different parts of the UI.

**Parent View:**

```

        {{ strtoupper($column) }}

            {{ $index }}
            {{ $row->name }}

```

**Child Component (`table.blade.php`):**

```

            @foreach($columns as $column)
                {{ $header($column) }}
            @endforeach

        @foreach($data as $index => $row)
            {{ $row($row, $index) }}
        @endforeach

```

This is especially handy for components like tables, accordions, tabs, and lists where the container structure is fixed but the content inside each section should be customizable by the consuming view.

---

Under the Hood (Blade Directives)
---------------------------------

[](#under-the-hood-blade-directives)

The syntactic sugar (`let="..."`) works by hooking into Blade's pre-compiler and transforming your tags into raw Blade directives provided by this package.

If you ever need to use the directives directly (for example, outside of an `` tag), you can use `@scopedslot` and `@endscopedslot`.

```
@scopedslot('slot', ($item, $index))
    {{ $index }}: {{ $item->name }}
@endscopedslot
```

### Parent Scope Preservation

[](#parent-scope-preservation)

When writing standard closures in PHP, you typically lose access to external variables unless you `use` them. This package intelligently binds the parent view's variable scope (`$__scopedSlotVars`) into the slot definition.

This means you can freely use variables from the parent view inside your scoped slot without any extra configuration!

```
@php $highlightColor = 'red'; @endphp

    {{ $user->name }}

```

License
-------

[](#license)

This package is open-sourced software licensed under the MIT license. Check the [LICENSE](LICENSE.md) file for more information.

Credits
-------

[](#credits)

- Built for [Laravel](https://laravel.com)
- Created by [Eduardo Ribeiro](https://github.com/eduardoribeirodev)

Support
-------

[](#support)

For issues, questions, or contributions, please visit the [GitHub repository](https://github.com/eduardoribeirodev/laravel-scoped-slots). Don't forget, Jesus loves you ❤️.

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance94

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

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

Total

2

Last Release

30d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/184874831?v=4)[Eduardo Ribeiro](/maintainers/eduardoribeirodev)[@eduardoribeirodev](https://github.com/eduardoribeirodev)

---

Tags

laravelEduardo Ribeirolaravel-scoped-slots

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/eduardoribeirodev-laravel-scoped-slots/health.svg)

```
[![Health](https://phpackages.com/badges/eduardoribeirodev-laravel-scoped-slots/health.svg)](https://phpackages.com/packages/eduardoribeirodev-laravel-scoped-slots)
```

###  Alternatives

[codewithdennis/filament-select-tree

The multi-level select field enables you to make single selections from a predefined list of options that are organized into multiple levels or depths.

329575.9k35](/packages/codewithdennis-filament-select-tree)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3915.5k](/packages/rawilk-profile-filament-plugin)

PHPackages © 2026

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