Skip to content

Commit 11d6bef

Browse files
Persaeustaylorotwell
authored andcommitted
Add methods withFragmentIdentifier and withoutFragmentIdentifier
1 parent 4e6b788 commit 11d6bef

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/Illuminate/Http/RedirectResponse.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,33 @@ public function withErrors($provider, $key = 'default')
145145
return $this;
146146
}
147147

148+
/**
149+
* Add fragment identifier to the url.
150+
*
151+
* @param string $fragmentIdentifier
152+
* @return $this
153+
*/
154+
public function withFragmentIdentifier(string $fragmentIdentifier)
155+
{
156+
// Remove any existing fragment identifier
157+
$this->withoutFragmentIdentifier();
158+
159+
// Strip superfluous "#" from the beginning of the fragment identifier
160+
$fragmentIdentifier = preg_replace('/^#/', '', $fragmentIdentifier);
161+
162+
return $this->setTargetUrl($this->getTargetUrl() . "#$fragmentIdentifier");
163+
}
164+
165+
/**
166+
* Remove any fragment identifier from the response url.
167+
*
168+
* @return $this
169+
*/
170+
public function withoutFragmentIdentifier()
171+
{
172+
return $this->setTargetUrl(explode('#', $this->getTargetUrl(), 2)[0]);
173+
}
174+
148175
/**
149176
* Parse the given errors into an appropriate value.
150177
*

0 commit comments

Comments
 (0)