Skip to content

Commit 7dd2905

Browse files
[9.x] Add getIntendedUrl method to redirector (#43938)
* [9.x] Add method to redirector * Update Redirector.php Co-authored-by: Taylor Otwell <[email protected]>
1 parent 3f1b0a2 commit 7dd2905

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

src/Illuminate/Routing/Redirector.php

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,6 @@ public function intended($default = '/', $status = 302, $headers = [], $secure =
113113
return $this->to($path, $status, $headers, $secure);
114114
}
115115

116-
/**
117-
* Set the intended url.
118-
*
119-
* @param string $url
120-
* @return $this
121-
*/
122-
public function setIntendedUrl($url)
123-
{
124-
$this->session->put('url.intended', $url);
125-
126-
return $this;
127-
}
128-
129116
/**
130117
* Create a new redirect response to the given path.
131118
*
@@ -263,4 +250,27 @@ public function setSession(SessionStore $session)
263250
{
264251
$this->session = $session;
265252
}
253+
254+
/**
255+
* Get the "intended" URL from the session.
256+
*
257+
* @return string|null
258+
*/
259+
public function getIntendedUrl()
260+
{
261+
return $this->session->get('url.intended');
262+
}
263+
264+
/**
265+
* Set the "intended" URL in the session.
266+
*
267+
* @param string $url
268+
* @return $this
269+
*/
270+
public function setIntendedUrl($url)
271+
{
272+
$this->session->put('url.intended', $url);
273+
274+
return $this;
275+
}
266276
}

tests/Routing/RoutingRedirectorTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,14 @@ public function testTemporarySignedRoute()
178178
$this->assertSame('http://foo.com/bar?signature=secret', $response->getTargetUrl());
179179
}
180180

181-
public function testItSetsValidIntendedUrl()
181+
public function testItSetsAndGetsValidIntendedUrl()
182182
{
183183
$this->session->shouldReceive('put')->once()->with('url.intended', 'http://foo.com/bar');
184+
$this->session->shouldReceive('get')->andReturn('http://foo.com/bar');
184185

185186
$result = $this->redirect->setIntendedUrl('http://foo.com/bar');
186187
$this->assertInstanceOf(Redirector::class, $result);
188+
189+
$this->assertSame('http://foo.com/bar', $this->redirect->getIntendedUrl());
187190
}
188191
}

0 commit comments

Comments
 (0)