From a9af37cef010488749b14c580aaa09d146cc04f6 Mon Sep 17 00:00:00 2001 From: Jacob Baker-Kretzmar Date: Fri, 9 Oct 2020 11:48:43 -0400 Subject: [PATCH 1/7] Change "namedRoutes" to "routes" --- .github/ISSUE_TEMPLATE/bug_report.md | 8 ++++---- README.md | 4 ++-- src/BladeRouteGenerator.php | 2 +- src/CommandRouteGenerator.php | 4 ++-- src/Ziggy.php | 2 +- src/js/route.js | 10 +++++----- tests/Unit/BladeRouteGeneratorTest.php | 12 ++++++------ tests/Unit/RouteModelBindingTest.php | 4 ++-- tests/Unit/ZiggyTest.php | 26 +++++++++++++------------- tests/fixtures/admin.js | 6 +++--- tests/fixtures/custom-url.js | 6 +++--- tests/fixtures/ziggy.js | 6 +++--- tests/js/route.test.js | 6 +++--- 13 files changed, 48 insertions(+), 48 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 1b91a1bd..826b0cbe 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -19,8 +19,8 @@ assignees: '' -- **Laravel version**: -- **Ziggy version**: +- **Laravel version**: +- **Ziggy version**: **Related routes**: @@ -30,9 +30,9 @@ assignees: '' Route::get('/', 'HomeController')->name('home'); ``` -**`Ziggy.namedRoutes`**: +**`Ziggy.routes`**: - + ```js { diff --git a/README.md b/README.md index 0cacce98..b41224c3 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ Note that you still have to generate your routes file with `php artisan ziggy:ge ## Usage -This package uses the `@routes` directive to inject a JavaScript object containing all of your application's routes, keyed by their names. This collection is available at `Ziggy.namedRoutes`. +This package uses the `@routes` directive to inject a JavaScript object containing all of your application's routes, keyed by their names. This collection is available at `Ziggy.routes`. The package also creates an optional `route()` JavaScript helper that functions like Laravel's PHP `route()` helper, which can be used to retrieve URLs by name and (optionally) parameters. @@ -261,7 +261,7 @@ Route::get('/login', function () { // ziggy.js var Ziggy = { - namedRoutes: {"home":{"uri":"\/","methods":["GET","HEAD"],"domain":null},"login":{"uri":"login","methods":["GET","HEAD"],"domain":null}}, + routes: {"home":{"uri":"\/","methods":["GET","HEAD"],"domain":null},"login":{"uri":"login","methods":["GET","HEAD"],"domain":null}}, baseUrl: 'http://ziggy.test/', baseProtocol: 'http', baseDomain: 'ziggy.test', diff --git a/src/BladeRouteGenerator.php b/src/BladeRouteGenerator.php index bf07a1a1..9e4112dc 100644 --- a/src/BladeRouteGenerator.php +++ b/src/BladeRouteGenerator.php @@ -36,7 +36,7 @@ private function generateMergeJavascript($json, $nonce) var routes = {$json}; for (var name in routes) { - Ziggy.namedRoutes[name] = routes[name]; + Ziggy.routes[name] = routes[name]; } })(); diff --git a/src/CommandRouteGenerator.php b/src/CommandRouteGenerator.php index 6c9ff604..48161a7f 100644 --- a/src/CommandRouteGenerator.php +++ b/src/CommandRouteGenerator.php @@ -43,8 +43,8 @@ public function generate($group = false) var Ziggy = {$payload}; if (typeof window !== 'undefined' && typeof window.Ziggy !== 'undefined') { - for (var name in window.Ziggy.namedRoutes) { - Ziggy.namedRoutes[name] = window.Ziggy.namedRoutes[name]; + for (var name in window.Ziggy.routes) { + Ziggy.routes[name] = window.Ziggy.routes[name]; } } diff --git a/src/Ziggy.php b/src/Ziggy.php index 26b882a2..3ceca4ff 100644 --- a/src/Ziggy.php +++ b/src/Ziggy.php @@ -142,7 +142,7 @@ public function toArray(): array 'defaultParameters' => method_exists(app('url'), 'getDefaultParameters') ? app('url')->getDefaultParameters() : [], - 'namedRoutes' => $this->applyFilters($this->group)->toArray(), + 'routes' => $this->applyFilters($this->group)->toArray(), ]; } diff --git a/src/js/route.js b/src/js/route.js index 39ac20c1..16496a1e 100644 --- a/src/js/route.js +++ b/src/js/route.js @@ -104,11 +104,11 @@ class Router extends String { this._config = config ?? Ziggy ?? globalThis?.Ziggy; if (name) { - if (!this._config.namedRoutes[name]) { + if (!this._config.routes[name]) { throw new Error(`Ziggy error: route '${name}' is not in the route list.`); } - this._route = new Route(name, this._config.namedRoutes[name], { ...this._config, absolute }); + this._route = new Route(name, this._config.routes[name], { ...this._config, absolute }); this._params = this._parse(params); } } @@ -156,7 +156,7 @@ class Router extends String { const url = window.location.host + window.location.pathname; // Find the first route that matches the current URL - const [current, route] = Object.entries(this._config.namedRoutes).find( + const [current, route] = Object.entries(this._config.routes).find( ([_, route]) => new Route(name, route, this._config).matchesUrl(url) ); @@ -188,7 +188,7 @@ class Router extends String { * @return {Object} */ get params() { - return this._dehydrate(this._config.namedRoutes[this.current()]); + return this._dehydrate(this._config.routes[this.current()]); } /** @@ -198,7 +198,7 @@ class Router extends String { * @return {Boolean} */ has(name) { - return Object.keys(this._config.namedRoutes).includes(name); + return Object.keys(this._config.routes).includes(name); } /** diff --git a/tests/Unit/BladeRouteGeneratorTest.php b/tests/Unit/BladeRouteGeneratorTest.php index c5453ae1..86f21b51 100644 --- a/tests/Unit/BladeRouteGeneratorTest.php +++ b/tests/Unit/BladeRouteGeneratorTest.php @@ -13,7 +13,7 @@ public function can_resolve_generator_from_container() { $generator = app(BladeRouteGenerator::class); - $this->assertStringContainsString('"namedRoutes":[]', $generator->generate()); + $this->assertStringContainsString('"routes":[]', $generator->generate()); } /** @test */ @@ -30,11 +30,11 @@ public function can_generate_named_routes() $output = (new BladeRouteGenerator)->generate(); $ziggy = json_decode(Str::after(Str::before($output, ";\n\n"), ' = '), true); - $this->assertCount(4, $ziggy['namedRoutes']); - $this->assertArrayHasKey('posts.index', $ziggy['namedRoutes']); - $this->assertArrayHasKey('posts.show', $ziggy['namedRoutes']); - $this->assertArrayHasKey('posts.store', $ziggy['namedRoutes']); - $this->assertArrayHasKey('postComments.index', $ziggy['namedRoutes']); + $this->assertCount(4, $ziggy['routes']); + $this->assertArrayHasKey('posts.index', $ziggy['routes']); + $this->assertArrayHasKey('posts.show', $ziggy['routes']); + $this->assertArrayHasKey('posts.store', $ziggy['routes']); + $this->assertArrayHasKey('postComments.index', $ziggy['routes']); } /** @test */ diff --git a/tests/Unit/RouteModelBindingTest.php b/tests/Unit/RouteModelBindingTest.php index b388a7b2..5cf4d420 100644 --- a/tests/Unit/RouteModelBindingTest.php +++ b/tests/Unit/RouteModelBindingTest.php @@ -160,7 +160,7 @@ public function can_merge_implicit_and_scoped_bindings() 'tag' => 'slug', ], ], - ], (new Ziggy)->toArray()['namedRoutes']); + ], (new Ziggy)->toArray()['routes']); } /** @test */ @@ -170,7 +170,7 @@ public function can_include_bindings_in_json() $this->markTestSkipped('Requires Laravel >=7'); } - $json = '{"baseUrl":"http:\/\/ziggy.dev","baseProtocol":"http","baseDomain":"ziggy.dev","basePort":null,"defaultParameters":[],"namedRoutes":{"users":{"uri":"users\/{user}","methods":["GET","HEAD"],"bindings":{"user":"uuid"}},"tags":{"uri":"tags\/{tag}","methods":["GET","HEAD"],"bindings":{"tag":"id"}},"tokens":{"uri":"tokens\/{token}","methods":["GET","HEAD"]},"users.numbers":{"uri":"users\/{user}\/{number}","methods":["GET","HEAD"],"bindings":{"user":"uuid"}},"posts":{"uri":"blog\/{category}\/{post}","methods":["GET","HEAD"],"bindings":{"category":"id","post":"slug"}},"posts.tags":{"uri":"blog\/{category}\/{post}\/{tag}","methods":["GET","HEAD"],"bindings":{"category":"id","post":"slug","tag":"slug"}}}}'; + $json = '{"baseUrl":"http:\/\/ziggy.dev","baseProtocol":"http","baseDomain":"ziggy.dev","basePort":null,"defaultParameters":[],"routes":{"users":{"uri":"users\/{user}","methods":["GET","HEAD"],"bindings":{"user":"uuid"}},"tags":{"uri":"tags\/{tag}","methods":["GET","HEAD"],"bindings":{"tag":"id"}},"tokens":{"uri":"tokens\/{token}","methods":["GET","HEAD"]},"users.numbers":{"uri":"users\/{user}\/{number}","methods":["GET","HEAD"],"bindings":{"user":"uuid"}},"posts":{"uri":"blog\/{category}\/{post}","methods":["GET","HEAD"],"bindings":{"category":"id","post":"slug"}},"posts.tags":{"uri":"blog\/{category}\/{post}\/{tag}","methods":["GET","HEAD"],"bindings":{"category":"id","post":"slug","tag":"slug"}}}}'; $this->assertSame($json, (new Ziggy)->toJson()); } diff --git a/tests/Unit/ZiggyTest.php b/tests/Unit/ZiggyTest.php index 6cd96736..52d49a79 100644 --- a/tests/Unit/ZiggyTest.php +++ b/tests/Unit/ZiggyTest.php @@ -95,7 +95,7 @@ public function can_set_included_routes_using_only_config() config(['ziggy' => [ 'only' => ['posts.s*', 'home'], ]]); - $routes = (new Ziggy)->toArray()['namedRoutes']; + $routes = (new Ziggy)->toArray()['routes']; $expected = [ 'home' => [ @@ -121,7 +121,7 @@ public function can_set_excluded_routes_using_except_config() config(['ziggy' => [ 'except' => ['posts.s*', 'home', 'admin.*'], ]]); - $routes = (new Ziggy)->toArray()['namedRoutes']; + $routes = (new Ziggy)->toArray()['routes']; $expected = [ 'posts.index' => [ @@ -146,7 +146,7 @@ public function returns_unfiltered_routes_when_both_only_and_except_configs_set( 'except' => ['posts.s*'], 'only' => ['home'], ]]); - $routes = (new Ziggy)->toArray()['namedRoutes']; + $routes = (new Ziggy)->toArray()['routes']; $expected = [ 'home' => [ @@ -188,7 +188,7 @@ public function can_set_included_routes_using_groups_config() 'authors' => ['home', 'posts.*'], ], ]]); - $routes = (new Ziggy('authors'))->toArray()['namedRoutes']; + $routes = (new Ziggy('authors'))->toArray()['routes']; $expected = [ 'home' => [ @@ -216,7 +216,7 @@ public function can_set_included_routes_using_groups_config() public function can_ignore_passed_group_not_set_in_config() { // The 'authors' group doesn't exist - $routes = (new Ziggy('authors'))->toArray()['namedRoutes']; + $routes = (new Ziggy('authors'))->toArray()['routes']; $expected = [ 'home' => [ @@ -256,7 +256,7 @@ public function can_include_middleware() config(['ziggy' => [ 'middleware' => true, ]]); - $routes = (new Ziggy)->toArray()['namedRoutes']; + $routes = (new Ziggy)->toArray()['routes']; $expected = [ 'home' => [ @@ -298,7 +298,7 @@ public function can_include_only_middleware_set_in_config() config(['ziggy' => [ 'middleware' => ['auth'], ]]); - $routes = (new Ziggy)->toArray()['namedRoutes']; + $routes = (new Ziggy)->toArray()['routes']; $expected = [ 'home' => [ @@ -341,7 +341,7 @@ public function can_order_fallback_routes_last() app('router')->get('/users', $this->noop())->name('users.index'); app('router')->getRoutes()->refreshNameLookups(); - $routes = (new Ziggy)->toArray()['namedRoutes']; + $routes = (new Ziggy)->toArray()['routes']; $expected = [ 'home' => [ @@ -396,7 +396,7 @@ public function route_payload_can_array_itself() 'baseDomain' => 'ziggy.dev', 'basePort' => null, 'defaultParameters' => [], - 'namedRoutes' => [ + 'routes' => [ 'home' => [ 'uri' => 'home', 'methods' => ['GET', 'HEAD'], @@ -424,7 +424,7 @@ public function route_payload_can_array_itself() ], ]; - $this->addPostCommentsRouteWithBindings($expected['namedRoutes']); + $this->addPostCommentsRouteWithBindings($expected['routes']); $this->assertSame($expected, $ziggy->toArray()); $this->assertSame($expected, $ziggy->jsonSerialize()); @@ -443,7 +443,7 @@ public function route_payload_can_json_itself() 'baseDomain' => 'ziggy.dev', 'basePort' => null, 'defaultParameters' => [], - 'namedRoutes' => [ + 'routes' => [ 'postComments.index' => [ 'uri' => 'posts/{post}/comments', 'methods' => ['GET', 'HEAD'], @@ -451,9 +451,9 @@ public function route_payload_can_json_itself() ], ]; - $this->addPostCommentsRouteWithBindings($expected['namedRoutes']); + $this->addPostCommentsRouteWithBindings($expected['routes']); - $json = '{"baseUrl":"http:\/\/ziggy.dev","baseProtocol":"http","baseDomain":"ziggy.dev","basePort":null,"defaultParameters":[],"namedRoutes":{"postComments.index":{"uri":"posts\/{post}\/comments","methods":["GET","HEAD"]}}}'; + $json = '{"baseUrl":"http:\/\/ziggy.dev","baseProtocol":"http","baseDomain":"ziggy.dev","basePort":null,"defaultParameters":[],"routes":{"postComments.index":{"uri":"posts\/{post}\/comments","methods":["GET","HEAD"]}}}'; if ($this->laravelVersion(7)) { $json = str_replace( diff --git a/tests/fixtures/admin.js b/tests/fixtures/admin.js index 3bdf27f8..ecd38705 100644 --- a/tests/fixtures/admin.js +++ b/tests/fixtures/admin.js @@ -1,8 +1,8 @@ -var Ziggy = {"baseUrl":"http:\/\/ziggy.dev","baseProtocol":"http","baseDomain":"ziggy.dev","basePort":null,"defaultParameters":[],"namedRoutes":{"admin.dashboard":{"uri":"admin","methods":["GET","HEAD"]}}}; +var Ziggy = {"baseUrl":"http:\/\/ziggy.dev","baseProtocol":"http","baseDomain":"ziggy.dev","basePort":null,"defaultParameters":[],"routes":{"admin.dashboard":{"uri":"admin","methods":["GET","HEAD"]}}}; if (typeof window !== 'undefined' && typeof window.Ziggy !== 'undefined') { - for (var name in window.Ziggy.namedRoutes) { - Ziggy.namedRoutes[name] = window.Ziggy.namedRoutes[name]; + for (var name in window.Ziggy.routes) { + Ziggy.routes[name] = window.Ziggy.routes[name]; } } diff --git a/tests/fixtures/custom-url.js b/tests/fixtures/custom-url.js index 7e57ae77..4f884e44 100644 --- a/tests/fixtures/custom-url.js +++ b/tests/fixtures/custom-url.js @@ -1,8 +1,8 @@ -var Ziggy = {"baseUrl":"http:\/\/example.org","baseProtocol":"http","baseDomain":"example.org","basePort":null,"defaultParameters":{"locale":"en"},"namedRoutes":{"postComments.index":{"uri":"posts\/{post}\/comments","methods":["GET","HEAD"]}}}; +var Ziggy = {"baseUrl":"http:\/\/example.org","baseProtocol":"http","baseDomain":"example.org","basePort":null,"defaultParameters":{"locale":"en"},"routes":{"postComments.index":{"uri":"posts\/{post}\/comments","methods":["GET","HEAD"]}}}; if (typeof window !== 'undefined' && typeof window.Ziggy !== 'undefined') { - for (var name in window.Ziggy.namedRoutes) { - Ziggy.namedRoutes[name] = window.Ziggy.namedRoutes[name]; + for (var name in window.Ziggy.routes) { + Ziggy.routes[name] = window.Ziggy.routes[name]; } } diff --git a/tests/fixtures/ziggy.js b/tests/fixtures/ziggy.js index e9baec84..e7997d01 100644 --- a/tests/fixtures/ziggy.js +++ b/tests/fixtures/ziggy.js @@ -1,8 +1,8 @@ -var Ziggy = {"baseUrl":"http:\/\/ziggy.dev","baseProtocol":"http","baseDomain":"ziggy.dev","basePort":null,"defaultParameters":[],"namedRoutes":{"postComments.index":{"uri":"posts\/{post}\/comments","methods":["GET","HEAD"]}}}; +var Ziggy = {"baseUrl":"http:\/\/ziggy.dev","baseProtocol":"http","baseDomain":"ziggy.dev","basePort":null,"defaultParameters":[],"routes":{"postComments.index":{"uri":"posts\/{post}\/comments","methods":["GET","HEAD"]}}}; if (typeof window !== 'undefined' && typeof window.Ziggy !== 'undefined') { - for (var name in window.Ziggy.namedRoutes) { - Ziggy.namedRoutes[name] = window.Ziggy.namedRoutes[name]; + for (var name in window.Ziggy.routes) { + Ziggy.routes[name] = window.Ziggy.routes[name]; } } diff --git a/tests/js/route.test.js b/tests/js/route.test.js index f2174b93..eb869819 100644 --- a/tests/js/route.test.js +++ b/tests/js/route.test.js @@ -13,7 +13,7 @@ const defaultZiggy = { baseDomain: 'ziggy.dev', basePort: null, defaultParameters: { locale: 'en' }, - namedRoutes: { + routes: { 'home': { uri: '/', methods: ['GET', 'HEAD'], @@ -405,7 +405,7 @@ describe('route()', () => { baseDomain: 'notYourAverage.dev', basePort: false, defaultParameters: { locale: 'en' }, - namedRoutes: { + routes: { 'tightenDev.packages.index': { uri: 'tightenDev/{dev}/packages', methods: ['GET', 'HEAD'], @@ -523,7 +523,7 @@ describe('current()', () => { baseProtocol: 'https', baseDomain: 'ziggy.dev', basePort: false, - namedRoutes: { + routes: { 'events.index': { uri: 'events', methods: ['GET', 'HEAD'], From ca993dbf243054428f76f2569f9ecbe1f9fe810e Mon Sep 17 00:00:00 2001 From: Jacob Baker-Kretzmar Date: Fri, 9 Oct 2020 11:49:16 -0400 Subject: [PATCH 2/7] Change "defaultParameters" to "defaults" --- README.md | 2 +- src/Ziggy.php | 2 +- src/js/route.js | 6 +++--- tests/Unit/RouteModelBindingTest.php | 2 +- tests/Unit/ZiggyTest.php | 6 +++--- tests/fixtures/admin.js | 2 +- tests/fixtures/custom-url.js | 2 +- tests/fixtures/ziggy.js | 2 +- tests/js/route.test.js | 6 +++--- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index b41224c3..394fd5bf 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ See the [Laravel documentation on default route parameter values](https://larave Default values work out of the box for Laravel versions >= 5.5.29, for previous versions you will need to set the default parameters by including this code somewhere in the same page as Ziggy's `@routes` Blade directive. ```js -Ziggy.defaultParameters = { +Ziggy.defaults = { // example locale: 'en', }; diff --git a/src/Ziggy.php b/src/Ziggy.php index 3ceca4ff..bf771bd7 100644 --- a/src/Ziggy.php +++ b/src/Ziggy.php @@ -139,7 +139,7 @@ public function toArray(): array 'baseProtocol' => $this->baseProtocol, 'baseDomain' => $this->baseDomain, 'basePort' => $this->basePort, - 'defaultParameters' => method_exists(app('url'), 'getDefaultParameters') + 'defaults' => method_exists(app('url'), 'getDefaultParameters') ? app('url')->getDefaultParameters() : [], 'routes' => $this->applyFilters($this->group)->toArray(), diff --git a/src/js/route.js b/src/js/route.js index 16496a1e..347e1aba 100644 --- a/src/js/route.js +++ b/src/js/route.js @@ -231,7 +231,7 @@ class Router extends String { params = ['string', 'number'].includes(typeof params) ? [params] : params; // Separate segments with and without defaults, and fill in the default values - const segments = route.parameterSegments.filter(({ name }) => !this._config.defaultParameters[name]); + const segments = route.parameterSegments.filter(({ name }) => !this._config.defaults[name]); if (Array.isArray(params)) { // If the parameters are an array they have to be in order, so we can transform them into @@ -266,8 +266,8 @@ class Router extends String { * @return {Object} Default route parameters. */ _defaults(route) { - return route.parameterSegments.filter(({ name }) => this._config.defaultParameters[name]) - .reduce((result, { name }, i) => ({ ...result, [name]: this._config.defaultParameters[name] }), {}); + return route.parameterSegments.filter(({ name }) => this._config.defaults[name]) + .reduce((result, { name }, i) => ({ ...result, [name]: this._config.defaults[name] }), {}); } /** diff --git a/tests/Unit/RouteModelBindingTest.php b/tests/Unit/RouteModelBindingTest.php index 5cf4d420..e1f8c191 100644 --- a/tests/Unit/RouteModelBindingTest.php +++ b/tests/Unit/RouteModelBindingTest.php @@ -170,7 +170,7 @@ public function can_include_bindings_in_json() $this->markTestSkipped('Requires Laravel >=7'); } - $json = '{"baseUrl":"http:\/\/ziggy.dev","baseProtocol":"http","baseDomain":"ziggy.dev","basePort":null,"defaultParameters":[],"routes":{"users":{"uri":"users\/{user}","methods":["GET","HEAD"],"bindings":{"user":"uuid"}},"tags":{"uri":"tags\/{tag}","methods":["GET","HEAD"],"bindings":{"tag":"id"}},"tokens":{"uri":"tokens\/{token}","methods":["GET","HEAD"]},"users.numbers":{"uri":"users\/{user}\/{number}","methods":["GET","HEAD"],"bindings":{"user":"uuid"}},"posts":{"uri":"blog\/{category}\/{post}","methods":["GET","HEAD"],"bindings":{"category":"id","post":"slug"}},"posts.tags":{"uri":"blog\/{category}\/{post}\/{tag}","methods":["GET","HEAD"],"bindings":{"category":"id","post":"slug","tag":"slug"}}}}'; + $json = '{"baseUrl":"http:\/\/ziggy.dev","baseProtocol":"http","baseDomain":"ziggy.dev","basePort":null,"defaults":[],"routes":{"users":{"uri":"users\/{user}","methods":["GET","HEAD"],"bindings":{"user":"uuid"}},"tags":{"uri":"tags\/{tag}","methods":["GET","HEAD"],"bindings":{"tag":"id"}},"tokens":{"uri":"tokens\/{token}","methods":["GET","HEAD"]},"users.numbers":{"uri":"users\/{user}\/{number}","methods":["GET","HEAD"],"bindings":{"user":"uuid"}},"posts":{"uri":"blog\/{category}\/{post}","methods":["GET","HEAD"],"bindings":{"category":"id","post":"slug"}},"posts.tags":{"uri":"blog\/{category}\/{post}\/{tag}","methods":["GET","HEAD"],"bindings":{"category":"id","post":"slug","tag":"slug"}}}}'; $this->assertSame($json, (new Ziggy)->toJson()); } diff --git a/tests/Unit/ZiggyTest.php b/tests/Unit/ZiggyTest.php index 52d49a79..533e3482 100644 --- a/tests/Unit/ZiggyTest.php +++ b/tests/Unit/ZiggyTest.php @@ -395,7 +395,7 @@ public function route_payload_can_array_itself() 'baseProtocol' => 'http', 'baseDomain' => 'ziggy.dev', 'basePort' => null, - 'defaultParameters' => [], + 'defaults' => [], 'routes' => [ 'home' => [ 'uri' => 'home', @@ -442,7 +442,7 @@ public function route_payload_can_json_itself() 'baseProtocol' => 'http', 'baseDomain' => 'ziggy.dev', 'basePort' => null, - 'defaultParameters' => [], + 'defaults' => [], 'routes' => [ 'postComments.index' => [ 'uri' => 'posts/{post}/comments', @@ -453,7 +453,7 @@ public function route_payload_can_json_itself() $this->addPostCommentsRouteWithBindings($expected['routes']); - $json = '{"baseUrl":"http:\/\/ziggy.dev","baseProtocol":"http","baseDomain":"ziggy.dev","basePort":null,"defaultParameters":[],"routes":{"postComments.index":{"uri":"posts\/{post}\/comments","methods":["GET","HEAD"]}}}'; + $json = '{"baseUrl":"http:\/\/ziggy.dev","baseProtocol":"http","baseDomain":"ziggy.dev","basePort":null,"defaults":[],"routes":{"postComments.index":{"uri":"posts\/{post}\/comments","methods":["GET","HEAD"]}}}'; if ($this->laravelVersion(7)) { $json = str_replace( diff --git a/tests/fixtures/admin.js b/tests/fixtures/admin.js index ecd38705..e846d3bc 100644 --- a/tests/fixtures/admin.js +++ b/tests/fixtures/admin.js @@ -1,4 +1,4 @@ -var Ziggy = {"baseUrl":"http:\/\/ziggy.dev","baseProtocol":"http","baseDomain":"ziggy.dev","basePort":null,"defaultParameters":[],"routes":{"admin.dashboard":{"uri":"admin","methods":["GET","HEAD"]}}}; +var Ziggy = {"baseUrl":"http:\/\/ziggy.dev","baseProtocol":"http","baseDomain":"ziggy.dev","basePort":null,"defaults":[],"routes":{"admin.dashboard":{"uri":"admin","methods":["GET","HEAD"]}}}; if (typeof window !== 'undefined' && typeof window.Ziggy !== 'undefined') { for (var name in window.Ziggy.routes) { diff --git a/tests/fixtures/custom-url.js b/tests/fixtures/custom-url.js index 4f884e44..bbedf680 100644 --- a/tests/fixtures/custom-url.js +++ b/tests/fixtures/custom-url.js @@ -1,4 +1,4 @@ -var Ziggy = {"baseUrl":"http:\/\/example.org","baseProtocol":"http","baseDomain":"example.org","basePort":null,"defaultParameters":{"locale":"en"},"routes":{"postComments.index":{"uri":"posts\/{post}\/comments","methods":["GET","HEAD"]}}}; +var Ziggy = {"baseUrl":"http:\/\/example.org","baseProtocol":"http","baseDomain":"example.org","basePort":null,"defaults":{"locale":"en"},"routes":{"postComments.index":{"uri":"posts\/{post}\/comments","methods":["GET","HEAD"]}}}; if (typeof window !== 'undefined' && typeof window.Ziggy !== 'undefined') { for (var name in window.Ziggy.routes) { diff --git a/tests/fixtures/ziggy.js b/tests/fixtures/ziggy.js index e7997d01..ed574a5c 100644 --- a/tests/fixtures/ziggy.js +++ b/tests/fixtures/ziggy.js @@ -1,4 +1,4 @@ -var Ziggy = {"baseUrl":"http:\/\/ziggy.dev","baseProtocol":"http","baseDomain":"ziggy.dev","basePort":null,"defaultParameters":[],"routes":{"postComments.index":{"uri":"posts\/{post}\/comments","methods":["GET","HEAD"]}}}; +var Ziggy = {"baseUrl":"http:\/\/ziggy.dev","baseProtocol":"http","baseDomain":"ziggy.dev","basePort":null,"defaults":[],"routes":{"postComments.index":{"uri":"posts\/{post}\/comments","methods":["GET","HEAD"]}}}; if (typeof window !== 'undefined' && typeof window.Ziggy !== 'undefined') { for (var name in window.Ziggy.routes) { diff --git a/tests/js/route.test.js b/tests/js/route.test.js index eb869819..015d896a 100644 --- a/tests/js/route.test.js +++ b/tests/js/route.test.js @@ -12,7 +12,7 @@ const defaultZiggy = { baseProtocol: 'https', baseDomain: 'ziggy.dev', basePort: null, - defaultParameters: { locale: 'en' }, + defaults: { locale: 'en' }, routes: { 'home': { uri: '/', @@ -197,7 +197,7 @@ describe('route()', () => { }); test('can error if a required parameter with a default has no default value', () => { - global.Ziggy.defaultParameters = {}; + global.Ziggy.defaults = {}; assert.throws( () => route('translatePosts.index').url(), @@ -404,7 +404,7 @@ describe('route()', () => { baseProtocol: 'http', baseDomain: 'notYourAverage.dev', basePort: false, - defaultParameters: { locale: 'en' }, + defaults: { locale: 'en' }, routes: { 'tightenDev.packages.index': { uri: 'tightenDev/{dev}/packages', From 6799f6ce2af2b9d614f573493585baad8c7b11e5 Mon Sep 17 00:00:00 2001 From: Jacob Baker-Kretzmar Date: Fri, 9 Oct 2020 11:52:38 -0400 Subject: [PATCH 3/7] Change "baseUrl" to "url" --- README.md | 2 +- src/Ziggy.php | 8 ++++---- src/js/route.js | 4 ++-- tests/Unit/RouteModelBindingTest.php | 2 +- tests/Unit/ZiggyTest.php | 6 +++--- tests/fixtures/admin.js | 2 +- tests/fixtures/custom-url.js | 2 +- tests/fixtures/ziggy.js | 2 +- tests/js/route.test.js | 20 ++++++++++---------- 9 files changed, 24 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 394fd5bf..bd06b703 100644 --- a/README.md +++ b/README.md @@ -262,7 +262,7 @@ Route::get('/login', function () { var Ziggy = { routes: {"home":{"uri":"\/","methods":["GET","HEAD"],"domain":null},"login":{"uri":"login","methods":["GET","HEAD"],"domain":null}}, - baseUrl: 'http://ziggy.test/', + url: 'http://ziggy.test/', baseProtocol: 'http', baseDomain: 'ziggy.test', basePort: false diff --git a/src/Ziggy.php b/src/Ziggy.php index bf771bd7..45d15ec1 100644 --- a/src/Ziggy.php +++ b/src/Ziggy.php @@ -13,7 +13,7 @@ class Ziggy implements JsonSerializable protected $baseDomain; protected $basePort; protected $baseProtocol; - protected $baseUrl; + protected $url; protected $group; protected $routes; @@ -21,9 +21,9 @@ public function __construct(string $group = null, string $url = null) { $this->group = $group; - $this->baseUrl = rtrim($url ?? config('app.url', url('/')), '/'); + $this->url = rtrim($url ?? config('app.url', url('/')), '/'); - tap(parse_url($this->baseUrl), function ($url) { + tap(parse_url($this->url), function ($url) { $this->baseProtocol = $url['scheme'] ?? 'http'; $this->baseDomain = $url['host'] ?? ''; $this->basePort = $url['port'] ?? null; @@ -135,7 +135,7 @@ protected function nameKeyedRoutes() public function toArray(): array { return [ - 'baseUrl' => $this->baseUrl, + 'url' => $this->url, 'baseProtocol' => $this->baseProtocol, 'baseDomain' => $this->baseDomain, 'basePort' => $this->basePort, diff --git a/src/js/route.js b/src/js/route.js index 347e1aba..3e8b4404 100644 --- a/src/js/route.js +++ b/src/js/route.js @@ -29,7 +29,7 @@ class Route { // domain configured we construct the origin with that, if not we use the app URL const origin = !this.config.absolute ? '' : this.definition.domain ? `${this.config.baseProtocol}://${this.definition.domain}${this.config.basePort ? `:${this.config.basePort}` : ''}` - : this.config.baseUrl; + : this.config.url; return `${origin}/${this.definition.uri}`; } @@ -313,7 +313,7 @@ class Router extends String { _dehydrate(route) { let pathname = window.location.pathname // If this Laravel app is in a subdirectory, trim the subdirectory from the path - .replace(this._config.baseUrl.replace(/^\w*:\/\/[^/]+/, ''), '') + .replace(this._config.url.replace(/^\w*:\/\/[^/]+/, ''), '') .replace(/^\/+/, ''); // Given part of a valid 'hydrated' URL containing all its parameter values, diff --git a/tests/Unit/RouteModelBindingTest.php b/tests/Unit/RouteModelBindingTest.php index e1f8c191..da2463db 100644 --- a/tests/Unit/RouteModelBindingTest.php +++ b/tests/Unit/RouteModelBindingTest.php @@ -170,7 +170,7 @@ public function can_include_bindings_in_json() $this->markTestSkipped('Requires Laravel >=7'); } - $json = '{"baseUrl":"http:\/\/ziggy.dev","baseProtocol":"http","baseDomain":"ziggy.dev","basePort":null,"defaults":[],"routes":{"users":{"uri":"users\/{user}","methods":["GET","HEAD"],"bindings":{"user":"uuid"}},"tags":{"uri":"tags\/{tag}","methods":["GET","HEAD"],"bindings":{"tag":"id"}},"tokens":{"uri":"tokens\/{token}","methods":["GET","HEAD"]},"users.numbers":{"uri":"users\/{user}\/{number}","methods":["GET","HEAD"],"bindings":{"user":"uuid"}},"posts":{"uri":"blog\/{category}\/{post}","methods":["GET","HEAD"],"bindings":{"category":"id","post":"slug"}},"posts.tags":{"uri":"blog\/{category}\/{post}\/{tag}","methods":["GET","HEAD"],"bindings":{"category":"id","post":"slug","tag":"slug"}}}}'; + $json = '{"url":"http:\/\/ziggy.dev","baseProtocol":"http","baseDomain":"ziggy.dev","basePort":null,"defaults":[],"routes":{"users":{"uri":"users\/{user}","methods":["GET","HEAD"],"bindings":{"user":"uuid"}},"tags":{"uri":"tags\/{tag}","methods":["GET","HEAD"],"bindings":{"tag":"id"}},"tokens":{"uri":"tokens\/{token}","methods":["GET","HEAD"]},"users.numbers":{"uri":"users\/{user}\/{number}","methods":["GET","HEAD"],"bindings":{"user":"uuid"}},"posts":{"uri":"blog\/{category}\/{post}","methods":["GET","HEAD"],"bindings":{"category":"id","post":"slug"}},"posts.tags":{"uri":"blog\/{category}\/{post}\/{tag}","methods":["GET","HEAD"],"bindings":{"category":"id","post":"slug","tag":"slug"}}}}'; $this->assertSame($json, (new Ziggy)->toJson()); } diff --git a/tests/Unit/ZiggyTest.php b/tests/Unit/ZiggyTest.php index 533e3482..cf9b904c 100644 --- a/tests/Unit/ZiggyTest.php +++ b/tests/Unit/ZiggyTest.php @@ -391,7 +391,7 @@ public function route_payload_can_array_itself() $ziggy = new Ziggy; $expected = [ - 'baseUrl' => 'http://ziggy.dev', + 'url' => 'http://ziggy.dev', 'baseProtocol' => 'http', 'baseDomain' => 'ziggy.dev', 'basePort' => null, @@ -438,7 +438,7 @@ public function route_payload_can_json_itself() ]]); $expected = [ - 'baseUrl' => 'http://ziggy.dev', + 'url' => 'http://ziggy.dev', 'baseProtocol' => 'http', 'baseDomain' => 'ziggy.dev', 'basePort' => null, @@ -453,7 +453,7 @@ public function route_payload_can_json_itself() $this->addPostCommentsRouteWithBindings($expected['routes']); - $json = '{"baseUrl":"http:\/\/ziggy.dev","baseProtocol":"http","baseDomain":"ziggy.dev","basePort":null,"defaults":[],"routes":{"postComments.index":{"uri":"posts\/{post}\/comments","methods":["GET","HEAD"]}}}'; + $json = '{"url":"http:\/\/ziggy.dev","baseProtocol":"http","baseDomain":"ziggy.dev","basePort":null,"defaults":[],"routes":{"postComments.index":{"uri":"posts\/{post}\/comments","methods":["GET","HEAD"]}}}'; if ($this->laravelVersion(7)) { $json = str_replace( diff --git a/tests/fixtures/admin.js b/tests/fixtures/admin.js index e846d3bc..bb391fc7 100644 --- a/tests/fixtures/admin.js +++ b/tests/fixtures/admin.js @@ -1,4 +1,4 @@ -var Ziggy = {"baseUrl":"http:\/\/ziggy.dev","baseProtocol":"http","baseDomain":"ziggy.dev","basePort":null,"defaults":[],"routes":{"admin.dashboard":{"uri":"admin","methods":["GET","HEAD"]}}}; +var Ziggy = {"url":"http:\/\/ziggy.dev","baseProtocol":"http","baseDomain":"ziggy.dev","basePort":null,"defaults":[],"routes":{"admin.dashboard":{"uri":"admin","methods":["GET","HEAD"]}}}; if (typeof window !== 'undefined' && typeof window.Ziggy !== 'undefined') { for (var name in window.Ziggy.routes) { diff --git a/tests/fixtures/custom-url.js b/tests/fixtures/custom-url.js index bbedf680..e6a8a3bb 100644 --- a/tests/fixtures/custom-url.js +++ b/tests/fixtures/custom-url.js @@ -1,4 +1,4 @@ -var Ziggy = {"baseUrl":"http:\/\/example.org","baseProtocol":"http","baseDomain":"example.org","basePort":null,"defaults":{"locale":"en"},"routes":{"postComments.index":{"uri":"posts\/{post}\/comments","methods":["GET","HEAD"]}}}; +var Ziggy = {"url":"http:\/\/example.org","baseProtocol":"http","baseDomain":"example.org","basePort":null,"defaults":{"locale":"en"},"routes":{"postComments.index":{"uri":"posts\/{post}\/comments","methods":["GET","HEAD"]}}}; if (typeof window !== 'undefined' && typeof window.Ziggy !== 'undefined') { for (var name in window.Ziggy.routes) { diff --git a/tests/fixtures/ziggy.js b/tests/fixtures/ziggy.js index ed574a5c..bd9792e2 100644 --- a/tests/fixtures/ziggy.js +++ b/tests/fixtures/ziggy.js @@ -1,4 +1,4 @@ -var Ziggy = {"baseUrl":"http:\/\/ziggy.dev","baseProtocol":"http","baseDomain":"ziggy.dev","basePort":null,"defaults":[],"routes":{"postComments.index":{"uri":"posts\/{post}\/comments","methods":["GET","HEAD"]}}}; +var Ziggy = {"url":"http:\/\/ziggy.dev","baseProtocol":"http","baseDomain":"ziggy.dev","basePort":null,"defaults":[],"routes":{"postComments.index":{"uri":"posts\/{post}\/comments","methods":["GET","HEAD"]}}}; if (typeof window !== 'undefined' && typeof window.Ziggy !== 'undefined') { for (var name in window.Ziggy.routes) { diff --git a/tests/js/route.test.js b/tests/js/route.test.js index 015d896a..11f2c3ff 100644 --- a/tests/js/route.test.js +++ b/tests/js/route.test.js @@ -8,7 +8,7 @@ const defaultWindow = { }; const defaultZiggy = { - baseUrl: 'https://ziggy.dev', + url: 'https://ziggy.dev', baseProtocol: 'https', baseDomain: 'ziggy.dev', basePort: null, @@ -287,7 +287,7 @@ describe('route()', () => { }); test('can generate a URL for an app installed in a subfolder', () => { - global.Ziggy.baseUrl = 'https://ziggy.dev/subfolder'; + global.Ziggy.url = 'https://ziggy.dev/subfolder'; equal( route('postComments.show', [1, { uuid: 'correct-horse-etc-etc' }]), @@ -352,7 +352,7 @@ describe('route()', () => { }); test('can generate a URL with a port', () => { - global.Ziggy.baseUrl = 'https://ziggy.dev:81'; + global.Ziggy.url = 'https://ziggy.dev:81'; global.Ziggy.baseDomain = 'ziggy.dev'; global.Ziggy.basePort = 81; @@ -363,13 +363,13 @@ describe('route()', () => { }); test('can handle trailing path segments in the base URL', () => { - global.Ziggy.baseUrl = 'https://test.thing/ab/cd'; + global.Ziggy.url = 'https://test.thing/ab/cd'; equal(route('events.venues.index', 1), 'https://test.thing/ab/cd/events/1/venues'); }); test('can URL-encode named parameters', () => { - global.Ziggy.baseUrl = 'https://test.thing/ab/cd'; + global.Ziggy.url = 'https://test.thing/ab/cd'; equal( route('events.venues.index', { event: 'Fun&Games' }), @@ -400,7 +400,7 @@ describe('route()', () => { test('can accept a custom Ziggy configuration object', () => { const config = { - baseUrl: 'http://notYourAverage.dev', + url: 'http://notYourAverage.dev', baseProtocol: 'http', baseDomain: 'notYourAverage.dev', basePort: false, @@ -420,7 +420,7 @@ describe('route()', () => { }); test('can extract parameters for an app installed in a subfolder', () => { - global.Ziggy.baseUrl = 'https://ziggy.dev/subfolder'; + global.Ziggy.url = 'https://ziggy.dev/subfolder'; global.window.location.href = 'https://ziggy.dev/subfolder/ph/en/products/4'; global.window.location.host = 'ziggy.dev'; @@ -430,7 +430,7 @@ describe('route()', () => { }); test('can extract parameters for an app installed in nested subfolders', () => { - global.Ziggy.baseUrl = 'https://ziggy.dev/nested/subfolder'; + global.Ziggy.url = 'https://ziggy.dev/nested/subfolder'; global.window.location.href = 'https://ziggy.dev/nested/subfolder/ph/en/products/4'; global.window.location.host = 'ziggy.dev'; @@ -519,7 +519,7 @@ describe('current()', () => { global.window.location.pathname = '/events/'; const config = { - baseUrl: 'https://ziggy.dev', + url: 'https://ziggy.dev', baseProtocol: 'https', baseDomain: 'ziggy.dev', basePort: false, @@ -570,7 +570,7 @@ describe('current()', () => { }); test('can check the current route name on a route with optional parameters in the middle of the URI', () => { - global.Ziggy.baseUrl = 'https://ziggy.dev/subfolder'; + global.Ziggy.url = 'https://ziggy.dev/subfolder'; // Missing the optional 'language' parameter (e.g. subfolder/ph/en/products...) global.window.location.href = 'https://ziggy.dev/subfolder/ph/products/4'; From 25dccaedf95290b7ff83dd37ee329e59adfa296f Mon Sep 17 00:00:00 2001 From: Jacob Baker-Kretzmar Date: Fri, 9 Oct 2020 11:55:07 -0400 Subject: [PATCH 4/7] Change "basePort" to "port" --- README.md | 2 +- src/Ziggy.php | 6 +++--- src/js/route.js | 2 +- tests/Unit/RouteModelBindingTest.php | 2 +- tests/Unit/ZiggyTest.php | 6 +++--- tests/fixtures/admin.js | 2 +- tests/fixtures/custom-url.js | 2 +- tests/fixtures/ziggy.js | 2 +- tests/js/route.test.js | 8 ++++---- 9 files changed, 16 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index bd06b703..abb3eb2f 100644 --- a/README.md +++ b/README.md @@ -265,7 +265,7 @@ var Ziggy = { url: 'http://ziggy.test/', baseProtocol: 'http', baseDomain: 'ziggy.test', - basePort: false + port: null }; export { diff --git a/src/Ziggy.php b/src/Ziggy.php index 45d15ec1..0509b44f 100644 --- a/src/Ziggy.php +++ b/src/Ziggy.php @@ -11,7 +11,7 @@ class Ziggy implements JsonSerializable { protected $baseDomain; - protected $basePort; + protected $port; protected $baseProtocol; protected $url; protected $group; @@ -26,7 +26,7 @@ public function __construct(string $group = null, string $url = null) tap(parse_url($this->url), function ($url) { $this->baseProtocol = $url['scheme'] ?? 'http'; $this->baseDomain = $url['host'] ?? ''; - $this->basePort = $url['port'] ?? null; + $this->port = $url['port'] ?? null; }); $this->routes = $this->nameKeyedRoutes(); @@ -138,7 +138,7 @@ public function toArray(): array 'url' => $this->url, 'baseProtocol' => $this->baseProtocol, 'baseDomain' => $this->baseDomain, - 'basePort' => $this->basePort, + 'port' => $this->port, 'defaults' => method_exists(app('url'), 'getDefaultParameters') ? app('url')->getDefaultParameters() : [], diff --git a/src/js/route.js b/src/js/route.js index 3e8b4404..73518a4a 100644 --- a/src/js/route.js +++ b/src/js/route.js @@ -28,7 +28,7 @@ class Route { // If we're building just a path there's no origin, otherwise: if this route has a // domain configured we construct the origin with that, if not we use the app URL const origin = !this.config.absolute ? '' : this.definition.domain - ? `${this.config.baseProtocol}://${this.definition.domain}${this.config.basePort ? `:${this.config.basePort}` : ''}` + ? `${this.config.baseProtocol}://${this.definition.domain}${this.config.port ? `:${this.config.port}` : ''}` : this.config.url; return `${origin}/${this.definition.uri}`; diff --git a/tests/Unit/RouteModelBindingTest.php b/tests/Unit/RouteModelBindingTest.php index da2463db..0c1a7ae6 100644 --- a/tests/Unit/RouteModelBindingTest.php +++ b/tests/Unit/RouteModelBindingTest.php @@ -170,7 +170,7 @@ public function can_include_bindings_in_json() $this->markTestSkipped('Requires Laravel >=7'); } - $json = '{"url":"http:\/\/ziggy.dev","baseProtocol":"http","baseDomain":"ziggy.dev","basePort":null,"defaults":[],"routes":{"users":{"uri":"users\/{user}","methods":["GET","HEAD"],"bindings":{"user":"uuid"}},"tags":{"uri":"tags\/{tag}","methods":["GET","HEAD"],"bindings":{"tag":"id"}},"tokens":{"uri":"tokens\/{token}","methods":["GET","HEAD"]},"users.numbers":{"uri":"users\/{user}\/{number}","methods":["GET","HEAD"],"bindings":{"user":"uuid"}},"posts":{"uri":"blog\/{category}\/{post}","methods":["GET","HEAD"],"bindings":{"category":"id","post":"slug"}},"posts.tags":{"uri":"blog\/{category}\/{post}\/{tag}","methods":["GET","HEAD"],"bindings":{"category":"id","post":"slug","tag":"slug"}}}}'; + $json = '{"url":"http:\/\/ziggy.dev","baseProtocol":"http","baseDomain":"ziggy.dev","port":null,"defaults":[],"routes":{"users":{"uri":"users\/{user}","methods":["GET","HEAD"],"bindings":{"user":"uuid"}},"tags":{"uri":"tags\/{tag}","methods":["GET","HEAD"],"bindings":{"tag":"id"}},"tokens":{"uri":"tokens\/{token}","methods":["GET","HEAD"]},"users.numbers":{"uri":"users\/{user}\/{number}","methods":["GET","HEAD"],"bindings":{"user":"uuid"}},"posts":{"uri":"blog\/{category}\/{post}","methods":["GET","HEAD"],"bindings":{"category":"id","post":"slug"}},"posts.tags":{"uri":"blog\/{category}\/{post}\/{tag}","methods":["GET","HEAD"],"bindings":{"category":"id","post":"slug","tag":"slug"}}}}'; $this->assertSame($json, (new Ziggy)->toJson()); } diff --git a/tests/Unit/ZiggyTest.php b/tests/Unit/ZiggyTest.php index cf9b904c..e98e2463 100644 --- a/tests/Unit/ZiggyTest.php +++ b/tests/Unit/ZiggyTest.php @@ -394,7 +394,7 @@ public function route_payload_can_array_itself() 'url' => 'http://ziggy.dev', 'baseProtocol' => 'http', 'baseDomain' => 'ziggy.dev', - 'basePort' => null, + 'port' => null, 'defaults' => [], 'routes' => [ 'home' => [ @@ -441,7 +441,7 @@ public function route_payload_can_json_itself() 'url' => 'http://ziggy.dev', 'baseProtocol' => 'http', 'baseDomain' => 'ziggy.dev', - 'basePort' => null, + 'port' => null, 'defaults' => [], 'routes' => [ 'postComments.index' => [ @@ -453,7 +453,7 @@ public function route_payload_can_json_itself() $this->addPostCommentsRouteWithBindings($expected['routes']); - $json = '{"url":"http:\/\/ziggy.dev","baseProtocol":"http","baseDomain":"ziggy.dev","basePort":null,"defaults":[],"routes":{"postComments.index":{"uri":"posts\/{post}\/comments","methods":["GET","HEAD"]}}}'; + $json = '{"url":"http:\/\/ziggy.dev","baseProtocol":"http","baseDomain":"ziggy.dev","port":null,"defaults":[],"routes":{"postComments.index":{"uri":"posts\/{post}\/comments","methods":["GET","HEAD"]}}}'; if ($this->laravelVersion(7)) { $json = str_replace( diff --git a/tests/fixtures/admin.js b/tests/fixtures/admin.js index bb391fc7..b3e037f7 100644 --- a/tests/fixtures/admin.js +++ b/tests/fixtures/admin.js @@ -1,4 +1,4 @@ -var Ziggy = {"url":"http:\/\/ziggy.dev","baseProtocol":"http","baseDomain":"ziggy.dev","basePort":null,"defaults":[],"routes":{"admin.dashboard":{"uri":"admin","methods":["GET","HEAD"]}}}; +var Ziggy = {"url":"http:\/\/ziggy.dev","baseProtocol":"http","baseDomain":"ziggy.dev","port":null,"defaults":[],"routes":{"admin.dashboard":{"uri":"admin","methods":["GET","HEAD"]}}}; if (typeof window !== 'undefined' && typeof window.Ziggy !== 'undefined') { for (var name in window.Ziggy.routes) { diff --git a/tests/fixtures/custom-url.js b/tests/fixtures/custom-url.js index e6a8a3bb..dc489a6a 100644 --- a/tests/fixtures/custom-url.js +++ b/tests/fixtures/custom-url.js @@ -1,4 +1,4 @@ -var Ziggy = {"url":"http:\/\/example.org","baseProtocol":"http","baseDomain":"example.org","basePort":null,"defaults":{"locale":"en"},"routes":{"postComments.index":{"uri":"posts\/{post}\/comments","methods":["GET","HEAD"]}}}; +var Ziggy = {"url":"http:\/\/example.org","baseProtocol":"http","baseDomain":"example.org","port":null,"defaults":{"locale":"en"},"routes":{"postComments.index":{"uri":"posts\/{post}\/comments","methods":["GET","HEAD"]}}}; if (typeof window !== 'undefined' && typeof window.Ziggy !== 'undefined') { for (var name in window.Ziggy.routes) { diff --git a/tests/fixtures/ziggy.js b/tests/fixtures/ziggy.js index bd9792e2..eebf1793 100644 --- a/tests/fixtures/ziggy.js +++ b/tests/fixtures/ziggy.js @@ -1,4 +1,4 @@ -var Ziggy = {"url":"http:\/\/ziggy.dev","baseProtocol":"http","baseDomain":"ziggy.dev","basePort":null,"defaults":[],"routes":{"postComments.index":{"uri":"posts\/{post}\/comments","methods":["GET","HEAD"]}}}; +var Ziggy = {"url":"http:\/\/ziggy.dev","baseProtocol":"http","baseDomain":"ziggy.dev","port":null,"defaults":[],"routes":{"postComments.index":{"uri":"posts\/{post}\/comments","methods":["GET","HEAD"]}}}; if (typeof window !== 'undefined' && typeof window.Ziggy !== 'undefined') { for (var name in window.Ziggy.routes) { diff --git a/tests/js/route.test.js b/tests/js/route.test.js index 11f2c3ff..ee25f74e 100644 --- a/tests/js/route.test.js +++ b/tests/js/route.test.js @@ -11,7 +11,7 @@ const defaultZiggy = { url: 'https://ziggy.dev', baseProtocol: 'https', baseDomain: 'ziggy.dev', - basePort: null, + port: null, defaults: { locale: 'en' }, routes: { 'home': { @@ -354,7 +354,7 @@ describe('route()', () => { test('can generate a URL with a port', () => { global.Ziggy.url = 'https://ziggy.dev:81'; global.Ziggy.baseDomain = 'ziggy.dev'; - global.Ziggy.basePort = 81; + global.Ziggy.port = 81; // route with no parameters equal(route('posts.index'), 'https://ziggy.dev:81/posts'); @@ -403,7 +403,7 @@ describe('route()', () => { url: 'http://notYourAverage.dev', baseProtocol: 'http', baseDomain: 'notYourAverage.dev', - basePort: false, + port: null, defaults: { locale: 'en' }, routes: { 'tightenDev.packages.index': { @@ -522,7 +522,7 @@ describe('current()', () => { url: 'https://ziggy.dev', baseProtocol: 'https', baseDomain: 'ziggy.dev', - basePort: false, + port: null, routes: { 'events.index': { uri: 'events', From 5d848212f90bc6d2f4dd41c885a79f501f4b5b97 Mon Sep 17 00:00:00 2001 From: Jacob Baker-Kretzmar Date: Fri, 9 Oct 2020 14:01:54 -0400 Subject: [PATCH 5/7] Formatting --- .github/ISSUE_TEMPLATE/bug_report.md | 4 ++-- README.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 826b0cbe..6a2d1c36 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -19,8 +19,8 @@ assignees: '' -- **Laravel version**: -- **Ziggy version**: +- **Laravel version**:  +- **Ziggy version**:  **Related routes**: diff --git a/README.md b/README.md index abb3eb2f..3d3b9e2e 100644 --- a/README.md +++ b/README.md @@ -265,7 +265,7 @@ var Ziggy = { url: 'http://ziggy.test/', baseProtocol: 'http', baseDomain: 'ziggy.test', - port: null + port: null, }; export { From ce3990e0b210e1f5fbbd6328d183093dc6a52875 Mon Sep 17 00:00:00 2001 From: Jacob Baker-Kretzmar Date: Fri, 9 Oct 2020 14:06:06 -0400 Subject: [PATCH 6/7] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a61d9c2..61125b33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ Breaking changes are marked with ⚠️. - Use [microbundle](https://github.com/developit/microbundle) instead of Webpack to build and distribute Ziggy ([#312](https://github.com/tighten/ziggy/pull/312)) - ⚠️ Default Ziggy's `baseUrl` to the value of the `APP_URL` environment variable instead of `url('/')` ([#334](https://github.com/tighten/ziggy/pull/334)) - ⚠️ Allow getting the route name with `current()` when the current URL has a query string ([#330](https://github.com/tighten/ziggy/pull/330)) +- ⚠️ Rename `namedRoutes` → `routes`, `defaultParameters` → `defaults`, `baseUrl` → `url`, and `basePort` → `port` ([#338](https://github.com/tighten/ziggy/pull/338)) **Deprecated** From 227d8559ad8eca5d9764fe6117ba562e6bdc13df Mon Sep 17 00:00:00 2001 From: Jacob Baker-Kretzmar Date: Fri, 23 Oct 2020 12:13:22 -0400 Subject: [PATCH 7/7] Add fix from #343 --- src/BladeRouteGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BladeRouteGenerator.php b/src/BladeRouteGenerator.php index f8e2dacc..bc57dbff 100644 --- a/src/BladeRouteGenerator.php +++ b/src/BladeRouteGenerator.php @@ -12,7 +12,7 @@ public function generate($group = false, $nonce = false) $nonce = $nonce ? ' nonce="' . $nonce . '"' : ''; if (static::$generated) { - return $this->generateMergeJavascript(json_encode($payload->toArray()['namedRoutes']), $nonce); + return $this->generateMergeJavascript(json_encode($payload->toArray()['routes']), $nonce); } $routeFunction = $this->getRouteFunction();