Download the PHP package exmachina/laravel-route-js without Composer
On this page you can find all versions of the php package exmachina/laravel-route-js. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download exmachina/laravel-route-js
More information about exmachina/laravel-route-js
Files in exmachina/laravel-route-js
Package laravel-route-js
Short Description Convert laravel's route to json files to be use in Javascript.
License MIT
Informations about the package laravel-route-js
Laravel routes to JS
Convert Laravel's routes to json
file to generate URL in Javascript
Features
-
Supports Laravel 5.8.x, 6.x, and 7.x
- Allow to specify what routes to be included/excluded.
Installation
In your Laravel app/config.php
, add the service provider:
Configuration
First, publish the default package's configuration:
The configuration will be published to config/route-js.php
.
Element | Type | Default | Description |
---|---|---|---|
dir |
string | resources/js/routes | Directory where the files will be saved. |
route.patterns |
array | [ ] | Routes to be included when generating route list. element type: String literals or RegExp pattern or both. |
route.exclude |
boolean | false | When set to true, exclude the routes provided in routes.patterns |
Usage
Generating the routes
This command will generate 2 files, the route list(laravel-routes.json
) and the js(laravel-routes.js
) file for the functionality. The default directory is resources/js/routes
.
Options
Option | Description |
---|---|
--dir |
Directory where the files will be saved |
--routes |
Routes to be included when generating route list. String literals or RegExp pattern or both. Can have multiple options for different patterns. e.g(--routes=admin* --routes=public.index) |
--exclude |
When provided, exclude the routes provided in--routes option or routes.patterns in config/route-js.php |
--exclude-js |
Only route list will be generate. The JS file that will act upon it will be excluded. |
--append |
Append the provides ROUTES to existing route list. |
JS Usage
Get URL using named route
Route with parameters
Parameter names will be the same in what you provided in your Laravel routes.
Route list
You can change the route list by calling setRoutes
method of Route
instance