Skip to content

Commit 82103fa

Browse files
committed
feat: add support for named routes on redirect
1 parent aa42931 commit 82103fa

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/Response.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,20 +260,24 @@ public function die($data, int $code = 500)
260260
* This method prepares this response to return an HTTP Redirect response
261261
* to the HTTP client.
262262
*
263-
* @param string $url The redirect destination
263+
* @param string|array $url The redirect destination
264264
* @param int $status The redirect HTTP status code
265265
*/
266-
public function redirect(string $url, int $status = 302)
266+
public function redirect($url, int $status = 302)
267267
{
268-
if (class_exists('Leaf\Eien\Server') && PHP_SAPI === 'cli') {
269-
\Leaf\Config::set('response.redirect', [$url, $status]);
270-
return;
268+
if (is_array($url)) {
269+
$url = app()->route($url[0]);
271270
}
272271

273272
if (class_exists('Leaf\App')) {
274273
$url = str_replace('//', '/', app()->getBasePath() . $url);
275274
}
276275

276+
if (class_exists('Leaf\Eien\Server') && PHP_SAPI === 'cli') {
277+
\Leaf\Config::set('response.redirect', [$url, $status]);
278+
return;
279+
}
280+
277281
Headers::status($status);
278282
Headers::set('Location', $url, true, $status);
279283
}

0 commit comments

Comments
 (0)