PHPackages                             kanuni/laravel-blade-anchor - 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. kanuni/laravel-blade-anchor

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

kanuni/laravel-blade-anchor
===========================

Extend your Laravel template files easily with the power of the anchor ⚓

v0.0.2(2y ago)13MITPHPPHP ^8.2

Since Mar 20Pushed 2y ago1 watchersCompare

[ Source](https://github.com/tjodalv/laravel-blade-anchor)[ Packagist](https://packagist.org/packages/kanuni/laravel-blade-anchor)[ Docs](https://github.com/kanuni/laravel-blade-anchor)[ GitHub Sponsors](https://github.com/tjodalv)[ RSS](/packages/kanuni-laravel-blade-anchor/feed)WikiDiscussions main Synced 1mo ago

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

Laravel Blade Anchor ⚓
======================

[](#laravel-blade-anchor-)

[![Latest Version on Packagist](https://camo.githubusercontent.com/57bec7a662f0536b5d867dc544a12ea2415ac3f1037d2e49b6617fe7926b584b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6b616e756e692f6c61726176656c2d626c6164652d616e63686f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/kanuni/laravel-blade-anchor)[![GitHub Tests Action Status](https://camo.githubusercontent.com/7d161a5938bf84e1f71bffac12c7c4afeac6cd3cbf35400c030ae6ed14d14c97/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6b616e756e692f6c61726176656c2d626c6164652d616e63686f722f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/kanuni/laravel-blade-anchor/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/36ba8607101347bd487ff6f0618cc5f2d99fd743436bc5d9e5ab58045e786ba8/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6b616e756e692f6c61726176656c2d626c6164652d616e63686f722f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/kanuni/laravel-blade-anchor/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/6bc81105c9f79703ac27ffd479a93ee75407c88c2e2da392394830ff36c66b21/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6b616e756e692f6c61726176656c2d626c6164652d616e63686f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/kanuni/laravel-blade-anchor)

Easily enable extending your application's user interface by third-party packages with anchors.

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

[](#installation)

You can install the package via composer:

```
composer require kanuni/laravel-blade-anchor
```

Usage
-----

[](#usage)

To allow third-party packages to extend your application's UI, you need to insert anchors into your Blade template files at the points where you want to permit these extensions.

### Placing anchors to enable UI extensions

[](#placing-anchors-to-enable-ui-extensions)

In your Blade file (e.g., `resources/views/welcome.blade.php`), you can add an anchor directive. For this example, let's create an anchor immediately after the opening `` tag:

```
...

    @anchor('begin.body')
    ...

```

You can name the anchor anything you like. In this example, we've named it `begin.body`.

### Creating an extender class

[](#creating-an-extender-class)

Once you've positioned your anchor, you can now register an extender class that will render a string or a Laravel View at that anchor point. Ideally, you should register your anchor extenders in the `boot()` method of your `AppServiceProvider` class.

But first, let's create a new anchor extender class using the Artisan command:

```
php artisan make:anchor-extender WelcomePageExtender

```

This command generates a new extender class in `app/BladeExtenders/WelcomePageExtender.php`. This class should implement the `__invoke()` method, whose return value will be rendered at the specified anchor point.

Here's an example of our newly created class:

```
namespace App\BladeExtenders;

use Illuminate\Contracts\Support\Renderable;
use Kanuni\LaravelBladeAnchor\Contracts\AnchorExtender;

class WelcomePageExtender implements AnchorExtender
{
    public function __invoke(?array $variables): string|Renderable|null
    {
        return 'This string will be injected at anchor point.';
    }
}
```

The `__invoke()` method can return a string or a View and accepts an optional array of variables available in your Blade template. If returning a Blade view, you can pass the variables to your view like this:

```
public function __invoke(?array $variables): string|Renderable|null
{
    return view('my-custom-blade-view', $variables);
}
```

It's also possible to inject any dependency classes into your extender's `__construct()` method:

```
class WelcomePageExtender implements AnchorExtender
{
    public function __construct(
        protected YourService $service
    )
    {}

    public function __invoke(?array $variables): string|Renderable|null
    {
        return "This are the results of your service: {$this->service->getResults()}";
    }
}
```

### Attaching the Extender to the Anchor

[](#attaching-the-extender-to-the-anchor)

Register your Blade extender in the `boot()` method of `app/Providers/AppServiceProvider` class using `LaravelBladeAnchor` facade. To do this, call the `registerExtender` method and provide the view name, anchor name, and extender class.

```
use Kanuni\LaravelBladeAnchor\Facades\LaravelBladeAnchor;
use App\BladeExtenders\WelcomePageExtender;

public function boot(): void
{
    LaravelBladeAnchor::registerExtender(
        view: 'welcome',
        anchor: 'begin.body',
        extenderClass: WelcomePageExtender::class,
    );
}
```

As demonstrated, anchor names are unique within each view. This means you can have anchors with the same name across two different views without any conflict.

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Zvonimir Lokmer](https://github.com/tjodalv)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

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

783d ago

### Community

Maintainers

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

---

Top Contributors

[![tjodalv](https://avatars.githubusercontent.com/u/2622065?v=4)](https://github.com/tjodalv "tjodalv (29 commits)")

---

Tags

laravelKanunilaravel-blade-anchor

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/kanuni-laravel-blade-anchor/health.svg)

```
[![Health](https://phpackages.com/badges/kanuni-laravel-blade-anchor/health.svg)](https://phpackages.com/packages/kanuni-laravel-blade-anchor)
```

###  Alternatives

[ryangjchandler/blade-capture-directive

Create inline partials in your Blade templates with ease.

8222.2M12](/packages/ryangjchandler-blade-capture-directive)[spatie/laravel-blade-comments

Add debug comments to your rendered output

177325.5k](/packages/spatie-laravel-blade-comments)[vormkracht10/laravel-mails

Laravel Mails can collect everything you might want to track about the mails that has been sent by your Laravel app.

24149.7k](/packages/vormkracht10-laravel-mails)[daikazu/laravel-glider

Start using Glide on-the-fly instantly in your Laravel blade templates.

882.3k](/packages/daikazu-laravel-glider)[combindma/dash-ui

A streamlined and stylish UI component library for Laravel Blade, crafted with TailwindCSS and AlpineJs for simplicity and elegance.

631.4k](/packages/combindma-dash-ui)

PHPackages © 2026

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