PHPackages                             chamnab/laroute - 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. chamnab/laroute

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

chamnab/laroute
===============

Access Laravels URL/Route helper functions, from JavaScript.

v1.2.3(1y ago)024MITPHPPHP &gt;=5.4.0

Since Mar 16Pushed 1y ago1 watchersCompare

[ Source](https://github.com/CHAMN4B/laroute)[ Packagist](https://packagist.org/packages/chamnab/laroute)[ RSS](/packages/chamnab-laroute/feed)WikiDiscussions main Synced 1mo ago

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

**This package is continuous development of [aaronlord/laroute](https://github.com/aaronlord/laroute)**.

Laroute
=======

[](#laroute)

[Laravel](http://laravel.com/) has some pretty sweet [helper functions](http://laravel.com/docs/helpers#urls) for generating urls/links and its auto-json-magic makes it building APIs super easy. It's my go-to choice for building single-page js apps, but routing can quickly become a bit of a pain.

Wouldn't it be amazing if we could access our Laravel routes from JavaScript?

This package allows us to port our routes over to JavaScript, and gives us a bunch of *very familiar* helper functions to use.

[![Laroute in action](laroute.png)](laroute.png)

[![Releases](https://camo.githubusercontent.com/e29ad4a21f77c298dc513b9d94af5e977c15f2bd0411128839d499770a30a095/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f4368616d6e61622f6c61726f7574652e7376673f7374796c653d666c61742d737175617265)](https://github.com/Chamnab/laroute/releases)[![Build Status](https://camo.githubusercontent.com/d439c5b05957c53fd18e74dfc6a32bd3249c8e2413670e5119a07b6774e960d3/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f4368616d6e61622f6c61726f7574652f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/Chamnab/laroute)[![StyleCI](https://camo.githubusercontent.com/9973e2d6cb24b4567d8b37eb45124ecca19727e3d2aade8324df5f55a207c09a/68747470733a2f2f7374796c6563692e696f2f7265706f732f3231343137303730302f736869656c64)](https://styleci.io/repos/214170700)[![Code Quality](https://camo.githubusercontent.com/b1df3b02cb40c485a0aab469b14b6460007fa82a021269ce0268a9aca0f7ff4d/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f4368616d6e61622f6c61726f7574652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/Chamnab/laroute/?branch=master)[![License](https://camo.githubusercontent.com/8d05cc7b3874b5db3b5b3cbf68e787d07696bab3e76a0b0751b3777baddeb497/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f4368616d6e61622f6c61726f7574652e7376673f7374796c653d666c61742d737175617265)](https://github.com/Chamnab/laroute/blob/master/LICENSE)[![Downloads](https://camo.githubusercontent.com/d76a97d7edc3973ebf5d78bec279aea2af6e28b23007f28a4432ead9f877d44b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f4368616d6e61622f6c61726f7574652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/chamnab/laroute)

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

[](#installation)

Install the usual [composer](https://getcomposer.org/) way.

```
composer require chamnab/laroute
```

### Configure (optional)

[](#configure-optional)

Copy the packages config files.

```
php artisan vendor:publish --provider='Chamnab\Laroute\LarouteServiceProvider'

```

###### app/config/packages/Chamnab/laroute/config.php

[](#appconfigpackageschamnablarouteconfigphp)

```
return [

    /*
     * The destination path for the javascript file.
     */
    'path' => 'public/js',

    /*
     * The destination filename for the javascript file.
     */
    'filename' => 'laroute',

    /*
     * The namespace for the helper functions. By default this will bind them to
     * `window.laroute`.
     */
    'namespace' => 'laroute',

    /*
     * Generate absolute URLs
     *
     * Set the Application URL in config/app.php
     */
    'absolute' => false,

    /*
     * The Filter Methode
     *
     * 'all' => All routes except "'laroute' => false"
     * 'only' => Only "'laroute' => true" routes
     * 'force' => All routes, ignored "laroute" route parameter
     */
    'filter' => 'all',

    /*
     * Action Namespace
     *
     * Set here your controller namespace (see RouteServiceProvider -> $namespace) for cleaner action calls
     * e.g. 'App\Http\Controllers'
     */
    'action_namespace' => '',

    /*
     * The path to the template `laroute.js` file. This is the file that contains
     * the ported helper Laravel url/route functions and the route data to go
     * with them.
     */
    'template' => 'vendor/chamnab/laroute/src/templates/laroute.js',

    /*
     * Appends a prefix to URLs. By default the prefix is an empty string.
    *
    */
    'prefix' => '',

];

```

### Generate the `laroute.js`

[](#generate-the-laroutejs)

To access the routes, we need to "port" them over to a JavaScript file:

```
php artisan laroute:generate

```

With the default configuration, this will create a `public/js/laroute.js` file to include in your page, or build.

```

```

**Note: You'll have to `laroute:generate` if you change your routes.**

JavaScript Documentation
------------------------

[](#javascript-documentation)

By default, all of the functions are under the `laroute` namespace. This documentation will stick with this convention.

### action

[](#action)

Generate a URL for a given controller action.

```
/**
 * laroute.action(action, [parameters = {}])
 *
 * action     : The action to route to.
 * parameters : Optional. key:value object literal of route parameters.
 */

laroute.action('HomeController@getIndex');
```

### route

[](#route)

Generate a URL for a given named route.

```
/**
 * laroute.route(name, [parameters = {}])
 *
 * name       : The name of the route to route to.
 * parameters : Optional. key:value object literal of route parameters.
 */

 laroute.route('Hello.{planet}', { planet : 'world' });
```

### url

[](#url)

Generate a fully qualified URL to the given path.

```
/**
 * laroute.url(name, [parameters = []])
 *
 * name       : The name of the route to route to.
 * parameters : Optional. value array of route parameters.
 */

 laroute.url('foo/bar', ['aaa', 'bbb']); // -> /foo/bar/aaa/bbb
```

### link\_to

[](#link_to)

Generate a html link to the given url.

```
/**
 * laroute.link_to(url, [title = url, attributes = {}]])
 *
 * url        : A relative url.
 * title      : Optional. The anchor text to display
 * attributes : Optional. key:value object literal of additional html attributes.
 */

 laroute.link_to('foo/bar', 'Foo Bar', { style : "color:#bada55;" });
```

### link\_to\_route

[](#link_to_route)

Generate a html link to the given route.

```
/**
 * laroute.link_to_route(name, [title = url, parameters = {}], attributes = {}]]])
 *
 * name       : The name of the route to route to.
 * title      : Optional. The anchor text to display
 * parameters : Optional. key:value object literal of route parameters.
 * attributes : Optional. key:value object literal of additional html attributes.
 */

 laroute.link_to_route('home', 'Home');
```

### link\_to\_action

[](#link_to_action)

Generate a html link to the given action.

```
/**
 * laroute.link_to_action(action, [title = url, parameters = {}], attributes = {}]]])
 *
 * action     : The action to route to.
 * title      : Optional. The anchor text to display
 * parameters : Optional. key:value object literal of route parameters.
 * attributes : Optional. key:value object literal of additional html attributes.
 */

 laroute.link_to_action('HelloController@planet', undefined, { planet : 'world' });
```

PHP Documentation
-----------------

[](#php-documentation)

### Ignore/Filter Routes

[](#ignorefilter-routes)

By default, all routes are available to laroute after a `php artisan laroute:generate`. However, it is sometimes desirable to have laroute ignore certain routes. You can do this by passing a `laroute` route option.

```
Route::get('/ignore-me', [
    'laroute' => false,
    'as'      => 'ignoreme',
    'uses'    => 'IgnoreController@me'
]);

Route::group(['laroute' => false], function () {
    Route::get('/groups-are-super-useful', 'GroupsController@index');
});
```

Licence
-------

[](#licence)

[View the licence in this repo.](https://github.com/Chamnab/laroute/blob/master/LICENSE)

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance45

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 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

7

Last Release

429d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3ad619101d428752c33c79d242a6af066fd1b76a39669566513012c29f8f77a7?d=identicon)[CHAMN4B](/maintainers/CHAMN4B)

---

Top Contributors

[![CHAMN4B](https://avatars.githubusercontent.com/u/89302223?v=4)](https://github.com/CHAMN4B "CHAMN4B (8 commits)")

---

Tags

laraveljavascriptroutesrouting

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/chamnab-laroute/health.svg)

```
[![Health](https://phpackages.com/badges/chamnab-laroute/health.svg)](https://phpackages.com/packages/chamnab-laroute)
```

###  Alternatives

[lord/laroute

Access Laravels URL/Route helper functions, from JavaScript.

8022.0M8](/packages/lord-laroute)[watson/active

Laravel helper for recognising the current route, controller and action

3253.6M14](/packages/watson-active)[te7a-houdini/laroute

Access Laravels URL/Route helper functions, from JavaScript.

33512.1k](/packages/te7a-houdini-laroute)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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