@@ -370,7 +370,7 @@ protected function prepareParameters($locale, $parameters)
370370
371371 foreach ($ parameters as $ key => $ parameter ) {
372372 if ($ parameter instanceof UrlRoutable) {
373- $ parameters [$ key ] = $ this ->getLocalizedRouteKey ($ parameter , $ locale );
373+ $ parameters [$ key ] = $ this ->getLocalizedRouteKey ($ key , $ parameter , $ locale );
374374 }
375375 }
376376
@@ -390,24 +390,47 @@ protected function getRouteParameters()
390390 /**
391391 * Get the localized route key from a model.
392392 *
393+ * @param string $key
393394 * @param \Illuminate\Contracts\Routing\UrlRoutable $model
394395 * @param string $locale
395396 *
396397 * @return string
397398 */
398- protected function getLocalizedRouteKey (UrlRoutable $ model , $ locale )
399+ protected function getLocalizedRouteKey ($ key , UrlRoutable $ model , $ locale )
399400 {
400401 $ originalLocale = App::getLocale ();
401402
402403 App::setLocale ($ locale );
403404
404- $ routeKey = $ model ->getRouteKey ();
405+ $ bindingField = $ this ->getBindingFieldFor ($ key , $ model );
406+ $ routeKey = $ model ->$ bindingField ;
405407
406408 App::setLocale ($ originalLocale );
407409
408410 return $ routeKey ;
409411 }
410412
413+ /**
414+ * Get the binding field for the current route.
415+ *
416+ * The binding field is the custom route key that you can define in your route:
417+ * Route::get('path/{model:key}')
418+ * If you did not use a custom key, use the default route key.
419+ *
420+ * @param string|int $key
421+ * @param \Illuminate\Contracts\Routing\UrlRoutable $model
422+ *
423+ * @return string|null
424+ */
425+ protected function getBindingFieldFor ($ key , UrlRoutable $ model )
426+ {
427+ if (App::version () < 7 ) {
428+ return $ model ->getRouteKeyName ();
429+ }
430+
431+ return $ this ->route ->bindingFieldFor ($ key ) ?: $ model ->getRouteKeyName ();
432+ }
433+
411434 /**
412435 * Get the locale that should be omitted in the URI path.
413436 *
0 commit comments