Download the PHP package fedeisas/laravel-js-routes without Composer
On this page you can find all versions of the php package fedeisas/laravel-js-routes. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download fedeisas/laravel-js-routes
More information about fedeisas/laravel-js-routes
Files in fedeisas/laravel-js-routes
Package laravel-js-routes
Short Description Laravel routes from Javascript
License MIT
Informations about the package laravel-js-routes
Laravel Javascript Routes
Why?
I love the Laravel 4 routing system and I often use named routes like route('users.show', array('id' => 1))
to generate http://domain.tld/users/1
.
With the amazing uprising of Javascript frameworks (AngularJS, EmberJS, Backbone, etc.) it's hard to track changes on your routes between the backend and the REST calls from your Javascript.
The goal of this library is to expose those named routes to your frontend so you can do: Router.route('users.show', {id: 1})
and get the same result.
Laravel 5
I haven't had the time to update this package to Laravel 5. Eventually, I'll create a new repo for that.
Requirements
- Laravel 4.1
Installation
Begin by installing this package through Composer. Edit your project's composer.json
file to require fedeisas/laravel-4-js-routes
.
Next, update Composer from the Terminal:
Once this operation completes, the final step is to add the service provider. Open app/config/app.php
, and add a new item to the providers array.
Usage
By default the command will generate a routes.js
file on your project root. This contains all named routes in your app.
That's it! You're all set to go. Run the artisan
command from the Terminal to see the new routes:javascript
commands.
Lazy Tip If you use Grunt, you could set up a watcher that runs this command whenever your routes files change.
Arguments
Name | Default | Description |
---|---|---|
name | routes.js | Output filename |
Options
Name | Default | Description |
---|---|---|
path | base_path() | Where to save the generated filename. (ie. public assets folder) |
filter | null | If you want only some routes to be available on JS, you can use a filter (like js-routable) to select only those |
object | Router | If you want to choose your own global JS object (to avoid collision) |
prefix | null | If you want to a path to prefix to all your routes |
Javascript usage
You have to include the generated file in your views (or your assets build process).
And then you have a Routes
object on your global scope. You can use it as:
Example:
If you assign parameters that are not present on the URI, they will get appended as a query string:
Contributing
In addition to a full test suite, there is Travis integration.
Found a bug?
Please, let me know! Send a pull request or a patch. Questions? Ask! I will respond to all filed issues.
Inspiration
Although no code was copied, this package is greatly inspired by FOSJsRoutingBundle for Symfony.
License
This package is open-sourced software licensed under the MIT license
All versions of laravel-js-routes with dependencies
illuminate/console Version ~4.1
illuminate/filesystem Version ~4.1
illuminate/routing Version ~4.1
php Version >=5.4.0