Skip to content

Commit

Permalink
Add methods withFragmentIdentifier and withoutFragmentIdentifier
Browse files Browse the repository at this point in the history
  • Loading branch information
Persaeus authored and taylorotwell committed Apr 23, 2020
1 parent 4e6b788 commit 11d6bef
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/Illuminate/Http/RedirectResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,33 @@ public function withErrors($provider, $key = 'default')
return $this;
}

/**
* Add fragment identifier to the url.
*
* @param string $fragmentIdentifier
* @return $this
*/
public function withFragmentIdentifier(string $fragmentIdentifier)
{
// Remove any existing fragment identifier
$this->withoutFragmentIdentifier();

// Strip superfluous "#" from the beginning of the fragment identifier
$fragmentIdentifier = preg_replace('/^#/', '', $fragmentIdentifier);

return $this->setTargetUrl($this->getTargetUrl() . "#$fragmentIdentifier");
}

/**
* Remove any fragment identifier from the response url.
*
* @return $this
*/
public function withoutFragmentIdentifier()
{
return $this->setTargetUrl(explode('#', $this->getTargetUrl(), 2)[0]);
}

/**
* Parse the given errors into an appropriate value.
*
Expand Down

0 comments on commit 11d6bef

Please sign in to comment.