Skip to content

Commit a62439e

Browse files
committed
Check if route is file and retrieve url without trailing slash
1 parent af04676 commit a62439e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/Routing/TrailingSlashUrlGenerator.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace GNAHotelSolutions\LaravelTrailingSlash\Routing;
44

55
use Illuminate\Routing\UrlGenerator;
6+
use Illuminate\Support\Str;
67

78
class TrailingSlashUrlGenerator extends UrlGenerator
89
{
@@ -17,10 +18,20 @@ class TrailingSlashUrlGenerator extends UrlGenerator
1718
*/
1819
public function format($root, $path, $route = '')
1920
{
20-
if (! config('laravel-trailing-slash.active', false)) {
21+
if ($this->pathIsFile($path) || $this->packageIsDisabled()) {
2122
return parent::format($root, $path, $route);
2223
}
2324

2425
return parent::format($root, $path, $route) . '/';
2526
}
27+
28+
private function pathIsFile($path): bool
29+
{
30+
return Str::contains(Str::afterLast($path, '/'), '.');
31+
}
32+
33+
private function packageIsDisabled(): bool
34+
{
35+
return ! config('laravel-trailing-slash.active', false);
36+
}
2637
}

0 commit comments

Comments
 (0)