Skip to content

Commit 86d6d9d

Browse files
author
Marc Cámara
committed
Fix issue when calling getLocalizedURL() on L5.5 (credits to leMaur)
1 parent b881e75 commit 86d6d9d

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
],
1414
"require": {
1515
"php": ">=7.0.0",
16-
"laravel/framework": "~5.2, ~5.3, ~5.4, ~5.5"
16+
"laravel/framework": "~5.2||~5.3||~5.4||~5.5"
1717
},
1818
"require-dev": {
1919
"orchestra/testbench-browser-kit": "~3.4",

src/Mcamara/LaravelLocalization/LaravelLocalization.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public function localizeURL($url = null, $locale = null)
211211
* @param string|bool $locale Locale to adapt, false to remove locale
212212
* @param string|false $url URL to adapt in the current language. If not passed, the current url would be taken.
213213
* @param array $attributes Attributes to add to the route, if empty, the system would try to extract them from the url.
214-
* @param bool $forceDefaultLocation Force to show default location even hideDefaultLocaleInURL set as TRUE
214+
* @param bool $forceDefaultLocation Force to show default location even hideDefaultLocaleInURL set as TRUE
215215
*
216216
* @throws SupportedLocalesNotDefined
217217
* @throws UnsupportedLocaleException
@@ -829,7 +829,7 @@ protected function extractAttributes($url = false, $locale = '')
829829
return [];
830830
}
831831

832-
$attributes = $this->router->current()->parameters();
832+
$attributes = $this->normalizeAttributes($this->router->current()->parameters());
833833
$response = event('routes.translation', [$locale, $attributes]);
834834

835835
if (!empty($response)) {
@@ -876,4 +876,19 @@ protected function unparseUrl($parsed_url)
876876

877877
return $url;
878878
}
879+
880+
/**
881+
* Normalize attributes gotten from request parameters.
882+
*
883+
* @param array $attributes The attributes
884+
* @return array The normalized attributes
885+
*/
886+
protected function normalizeAttributes($attributes)
887+
{
888+
if (array_key_exists('data', $attributes) && is_array($attributes['data']) && ! count($attributes['data'])) {
889+
$attributes['data'] = null;
890+
return $attributes;
891+
}
892+
return $attributes;
893+
}
879894
}

0 commit comments

Comments
 (0)