PHPackages                             jshannon63/laravel-baton - 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. jshannon63/laravel-baton

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

jshannon63/laravel-baton
========================

Share named routes and other collection data to Javascript from your Laravel Blade views

v0.1.0(8y ago)122MITPHPPHP &gt;=7.0.0

Since Sep 6Pushed 8y ago1 watchersCompare

[ Source](https://github.com/jshannon63/laravel-baton)[ Packagist](https://packagist.org/packages/jshannon63/laravel-baton)[ RSS](/packages/jshannon63-laravel-baton/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

Baton - Share Laravel named routes and other collection data with javascript
============================================================================

[](#baton---share-laravel-named-routes-and-other-collection-data-with-javascript)

Baton registers a global view composer which will enable passing of the Baton collection to all views. The Baton collection contains all named routes (optional) as well as any additional values you wish to add to the collection prior to rendering the view.

If you are looking for a more flexible package which is specifically designed to pass only named routes to the client I would recommend [tightenco/ziggy](https://github.com/tightenco/ziggy). It gives many more options for that function. Baton is a good choce when you would like the flexibility of working with collections and quickly/easily passing that data to javascript.

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

[](#installation)

```
composer require jshannon63/laravel-baton

```

Laravel 5.5+ will automatically take care of the service provider registration.

Usage
-----

[](#usage)

### Configuration:

[](#configuration)

Baton will by default pass named routes to the rendered view. If you wish to disable this action, add the following line to your .env file.

```
BATON_ROUTES = false    // Disable returning named routes in Baton
```

### By default, Baton contains a collection of named routes called "routes":

[](#by-default-baton-contains-a-collection-of-named-routes-called-routes)

```
array:1 [▼
  "routes" => Collection {#201 ▼
    #items: array:9 [▼
      "blogs" => Collection {#206 ▼
        #items: array:2 [▼
          "uri" => "blog"
          "methods" => array:2 [▼
            0 => "GET"
            1 => "HEAD"
          ]
        ]
      }
      "login" => Collection {#205 ▶}
      "logout" => Collection {#216 ▶}
      "register" => Collection {#217 ▶}
      "password.request" => Collection {#218 ▶}
      "password.email" => Collection {#219 ▶}
      "password.reset" => Collection {#220 ▶}
      "home" => Collection {#221 ▶}
      "about" => Collection {#222 ▶}
    ]
  }
]
```

### Adding additional data to Baton before passing on to the view

[](#adding-additional-data-to-baton-before-passing-on-to-the-view)

Baton is an extension of the Collection class. You may add, manuipulate or remove any collection elements using the methods of Illuminate\\Support\\Collection.

#### Example to add a Blog article to Baton:

[](#example-to-add-a-blog-article-to-baton)

First, create a real time Facade for Baton as follows

```
use Facades/Jshannon63/Baton/Baton;
```

Then access the put method of Baton using the Facade.

```
Baton::put( 'article', Blog::find(1) );
```

### Rendering Baton data in a view

[](#rendering-baton-data-in-a-view)

The {!!baton!!} declaration will be replaced with a javascript compliant variable declaration. Notice that the syntax used to embed our $baton variable in the blade view will prevent escaping by the htmlspecialchars() function. You may place {!!$baton!!} anywhere in your view. You may choose to make it available as window.baton or even within a Vue component or other javascript implementation.

This is before rendering...

```
...

    {!!$baton!!}

```

This is after rendering...

```
...

    var baton = JSON.parse('{"routes":{"blogs":{"uri":"blog","methods":["GET","HEAD"]},"login":{"uri":"login","methods":["GET","HEAD"]},"logout":{"uri":"logout","methods":["POST"]},"register":{"uri":"register","methods":["GET","HEAD"]},"password.request":{"uri":"password\/reset","methods":["GET","HEAD"]},"password.email":{"uri":"password\/email","methods":["POST"]},"password.reset":{"uri":"password\/reset\/{token}","methods":["GET","HEAD"]},"home":{"uri":"home","methods":["GET","HEAD"]},"about":{"uri":"about","methods":["GET","HEAD"]}}}');

```

In the above example, the blog route uri is available on the client side as window.baton.routes.blogs

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

[](#contributing)

If you would like to contribute refer to CONTRIBUTING.md

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

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

Unknown

Total

1

Last Release

3171d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

bladecollectionjavascriptlaravelrouteshare-routeslaraveljavascriptroutesviewvue

### Embed Badge

![Health badge](/badges/jshannon63-laravel-baton/health.svg)

```
[![Health](https://phpackages.com/badges/jshannon63-laravel-baton/health.svg)](https://phpackages.com/packages/jshannon63-laravel-baton)
```

###  Alternatives

[tightenco/ziggy

Use your Laravel named routes in JavaScript.

4.3k41.6M267](/packages/tightenco-ziggy)[vikdiesel/admin-one-laravel-dashboard

Admin One - Laravel Dashboard Preset (SPA)

1435.5k](/packages/vikdiesel-admin-one-laravel-dashboard)[itstructure/laravel-grid-view

Grid view for laravel framework

2546.6k2](/packages/itstructure-laravel-grid-view)

PHPackages © 2026

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