2017 © Pedro Peláez
 

library laroute

Access Laravels URL/Route helper functions, from JavaScript.

image

dogadogmbh/laroute

Access Laravels URL/Route helper functions, from JavaScript.

  • Monday, May 14, 2018
  • by darthsoup
  • Repository
  • 2 Watchers
  • 0 Stars
  • 376 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 92 Forks
  • 0 Open issues
  • 21 Versions
  • 422 % Grown

The README.md

Laroute

Forked from aaronlord/laroute - because of the inactivity of the maintainer

Laravel has some pretty sweet helper functions 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., (*1)

Wouldn't it be amazing if we could access our Laravel routes from JavaScript?, (*2)

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

Laroute in action, (*4)

Installation

Install the usual composer way., (*5)

composer require dogado/laroute

After Laravel 5.5

You don't have to do anything else here., (*6)

Before Laravel 5.5

Now all you have to do is add the service provider of the package and alias the package. To do this, open your config/app.php file., (*7)

Add a new line to the providers array:, (*8)

Dogado\Laroute\LarouteServiceProvider::clas

Configure (optional)

Copy the packages config files., (*9)

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

Generate the laroute.js

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

php artisan laroute:generate

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

<script src="/js/laroute.js"></script>

Note: You'll have to laroute:generate if you change your routes., (*12)

JavaScript Documentation

By default, all of the functions are under the laroute namespace. This documentation will stick with this convention., (*13)

route

Generate a URL for a given named route., (*14)

/**
 * 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

Generate a fully qualified URL to the given path., (*15)

/**
 * 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

Generate a html link to the given url., (*16)

/**
 * 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;" });

Generate a html link to the given route., (*17)

/**
 * 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');

PHP Documentation

Ignore/Filter 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., (*18)

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

View the licence in this repo., (*19)

The Versions

14/05 2018
14/05 2018
12/08 2016
24/12 2015

v2.2.0

2.2.0.0

Access Laravels URL/Route helper functions, from JavaScript.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Aaron Lord

laravel javascript routing routes

10/06 2015

v2.1.0

2.1.0.0

Access Laravels URL/Route helper functions, from JavaScript.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Aaron Lord

laravel javascript routing routes

13/02 2015

v2.0.0

2.0.0.0

Access Laravels URL/Route helper functions, from JavaScript.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Aaron Lord

laravel javascript routing routes

23/07 2014

v1.3.2

1.3.2.0

Access Laravels URL/Route helper functions, from JavaScript.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Aaron Lord

laravel javascript routing routes

18/07 2014

v1.3.1

1.3.1.0

Access Laravels URL/Route helper functions, from JavaScript.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Aaron Lord

laravel javascript routing routes

18/07 2014

v1.2.2

1.2.2.0

Access Laravels URL/Route helper functions, from JavaScript.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Aaron Lord

laravel javascript routing routes

18/07 2014

v1.3.0

1.3.0.0

Access Laravels URL/Route helper functions, from JavaScript.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Aaron Lord

laravel javascript routing routes

18/07 2014

v1.2.1

1.2.1.0

Access Laravels URL/Route helper functions, from JavaScript.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Aaron Lord

laravel javascript routing routes

04/04 2014

v1.2

1.2.0.0

Access Laravels URL/Route helper functions, from JavaScript.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Aaron Lord

laravel javascript routing routes

14/03 2014

v1.1

1.1.0.0

Access Laravels URL/Route helper functions, from JavaScript.

  Sources   Download

The Requires

 

The Development Requires

by Aaron Lord

laravel javascript routing routes

14/03 2014

v1.0

1.0.0.0

Access Laravels URL/Route helper functions, from JavaScript.

  Sources   Download

The Requires

 

The Development Requires

by Aaron Lord

laravel javascript routing routes