macellan/laravel-js-routes
最新稳定版本:2.3
Composer 安装命令:
composer require macellan/laravel-js-routes
包简介
Laravel routes from Javascript
README 文档
README
Why
I love the Laravel 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.
Installation
You can install this package via composer:
composer require macellan/laravel-js-routes
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.
php artisan routes:javascript
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) |
| 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).
<script src="/path/to/routes.js" type="text/javascript">
And then you have a Routes object on your global scope. You can use it as:
Router.route(route_name, params)
Example:
Router.route('users.show', {id: 1}) // returns http://dommain.tld/users/1
If you assign parameters that are not present on the URI, they will get appended as a query string:
Router.route('users.show', {id: 1, name: 'John', order: 'asc'}) // returns http://dommain.tld/users/1?name=John&order=asc
Contributing
composer install --dev ./vendor/bin/phpunit
npm install -g grunt-cli npm install grunt travis --verbose
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
统计信息
- 总下载量: 23.12k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-04