Skip to content

Commit

Permalink
Merge pull request #12 from iMi-digital/11-fix-route
Browse files Browse the repository at this point in the history
#11 Fix SID appending for to/previous
  • Loading branch information
cscheibelhut authored Jul 25, 2022
2 parents b6d04c5 + 54579f0 commit edce672
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ To use SessionIDs in URLs add the middleware `urlsession` (if you registered the

URLs generated with Laravel's URL function (for example `URL::to()`) will now have a session ID appended.

Deprecated (use route groups instead):

If direct path's are or the `previous()` method is used, the SID is always added, because no route is known.
If you would like to generate URLs without a session ID, add a `NO_ADD_SID` parameter:

{{ URL::to('/', ['NO_ADD_SID' => true]) }}
Expand Down
5 changes: 3 additions & 2 deletions src/UrlGeneratorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ class UrlGeneratorService extends UrlGenerator
public function addSid($url, ?\Illuminate\Routing\Route $route = null)
{
// Only apply transsid to routes/routegroups with the urlsession middleware.
if ($route === null || !is_array($route->getAction('middleware')) || !in_array(UrlSession::class, $route->getAction('middleware'))) {
// or if no route is known (for example whne processing paths)
if ($route !== null && ( !is_array($route->getAction('middleware')) || !in_array(UrlSession::class, $route->getAction('middleware')) )) {
return $url;
}

if (strpos($url, \Config::get('session.cookie')) !== false) {
return $url;
}

$separator = (strpos($url, '?') !== false) ? '&' : '?';
$url .= $separator . \Config::get('session.cookie') . '=' . \Session::getId();

Expand Down

0 comments on commit edce672

Please sign in to comment.