From 8668c7e8dfd16f3ae60660c3d41dc339a1e16c12 Mon Sep 17 00:00:00 2001 From: jakebathman Date: Fri, 16 Feb 2018 23:30:17 -0600 Subject: [PATCH 1/2] Add documentation New documentation for: * Artisan command * Environment detection when loading route.js * Optional config skip-route-function --- README.md | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 26be15a7..ee9f750b 100644 --- a/README.md +++ b/README.md @@ -169,7 +169,71 @@ To achieve this simple call `.url()` on your route: ```javascript route('home').url() -// http://myapp.dev/ +// http://myapp.local/ +``` + +## Artisan command + +Ziggy publishes an artisan command to generate a `ziggy.js` routes file, which can be used as part of an asset pipeline such as `Elixir` or `Mix`. + +You can run `php artisan ziggy:generate` in your project to generate a static routes file in `resources/assets/js/ziggy.js`. + +Optionally, include a second parameter to override the path and file names (you must pass a file name with the path): + +``` +php artisan ziggy:generate "resources/foo.js" +``` + +Example `ziggy.js`, where the named routes `home` and `login` exist in `routes/web.php`: + +```php +// routes/web.php + +name('home'); + +Route::get('/login', function () { + return view('login'); +})->name('login'); +``` + +```js +// ziggy.js + +var Ziggy = { + namedRoutes: {"home":{"uri":"\/","methods":["GET","HEAD"],"domain":null},"login":{"uri":"login","methods":["GET","HEAD"],"domain":null}}, + baseUrl: 'http://myapp.local/', + baseProtocol: 'http', + baseDomain: 'myapp.local', + basePort: false +}; + +export { + Ziggy +} +``` + +## Environment-based loading of minified route helper file + +When loading the blade helper file, Ziggy will detect the current environment and minify the output if `APP_ENV` is not `local`. + +When this happens, `ziggy.min.js` will be loaded. Otherwise, `ziggy.js` will be used. + +## Optional `route` helper + +If you only want routes available through `@routes`, but don't need the `route` helper function, you can include `skip-route-function` in your config and set it to `true`: + +```php +// config/ziggy.php + + true +]; ``` ## Contributions & Credits From 4105a83ba3253d48023a21f8e8f02fe1c7090336 Mon Sep 17 00:00:00 2001 From: Daniel Coulbourne Date: Sat, 17 Feb 2018 00:56:34 -0500 Subject: [PATCH 2/2] Remove reference to Elixer. Elixer is the old name for what is now Laravel Mix so I'm just going to mention the latest name. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ee9f750b..f6be04a0 100644 --- a/README.md +++ b/README.md @@ -174,7 +174,7 @@ route('home').url() ## Artisan command -Ziggy publishes an artisan command to generate a `ziggy.js` routes file, which can be used as part of an asset pipeline such as `Elixir` or `Mix`. +Ziggy publishes an artisan command to generate a `ziggy.js` routes file, which can be used as part of an asset pipeline such as [Laravel Mix](https://laravel.com/docs/mix). You can run `php artisan ziggy:generate` in your project to generate a static routes file in `resources/assets/js/ziggy.js`.