Skip to content

Commit

Permalink
Prevent problems for URL params that do not exist in Post model (#514)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjauvin authored Jul 31, 2020
1 parent dd4e121 commit 7e1a9d4
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions components/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ public function init()
Event::listen('translate.localePicker.translateParams', function ($page, $params, $oldLocale, $newLocale) {
$newParams = $params;

foreach ($params as $paramName => $paramValue) {
$records = BlogPost::transWhere($paramName, $paramValue, $oldLocale)->first();

if (isset($params['slug'])) {
$records = BlogPost::transWhere('slug', $params['slug'], $oldLocale)->first();
if ($records) {
$records->translateContext($newLocale);
$newParams[$paramName] = $records[$paramName];
$newParams['slug'] = $records['slug'];
}
}

return $newParams;
});
}
Expand Down

0 comments on commit 7e1a9d4

Please sign in to comment.