Skip to content

Commit

Permalink
code cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jul 18, 2016
1 parent d01a835 commit a8ca2b7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/Illuminate/Routing/UrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,14 @@ public function previous($fallback = false)
$referrer = $this->request->headers->get('referer');

$url = $referrer ? $this->to($referrer) : $this->getPreviousUrlFromSession();
$fallback = value($fallback) ?: $this->to('/');

return $url ?: $fallback;
if ($url) {
return $url;
} elseif ($fallback) {
return $this->to($fallback);

This comment has been minimized.

Copy link
@CupOfTea696

CupOfTea696 Jul 19, 2016

Contributor

This only allows strings as a fallback which then will be passed to the to method. The reason I used value($fallback) is so that you can for example do something like $url->previous(function() use ($url) { return $url->route('my.named.route'); });
#14207

This comment has been minimized.

Copy link
@taylorotwell

taylorotwell Jul 19, 2016

Author Member

Why do that when you could just do $url->previous($url->route('my.named.route'));?

This comment has been minimized.

Copy link
@CupOfTea696

CupOfTea696 Jul 19, 2016

Contributor

Oh, I didn't realise $url->to worked with full urls.

} else {
return $this->to('/');
}
}

/**
Expand Down
4 changes: 1 addition & 3 deletions tests/Routing/RoutingUrlGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,7 @@ public function testPrevious()
$url->getRequest()->headers->remove('referer');
$this->assertEquals($url->to('/'), $url->previous());

$this->assertEquals($url->to('/foo'), $url->previous(function () use ($url) {
return $url->to('/foo');
}));
$this->assertEquals($url->to('/foo'), $url->previous('/foo'));
}
}

Expand Down

0 comments on commit a8ca2b7

Please sign in to comment.