blessing-skin-server/app/Http/Middleware/RedirectIfUrlEndsWithSlash.php
Pig Fang 3cf19d8656
Apply fixes from StyleCI (#11)
This pull request applies code style fixes from an analysis carried out by [StyleCI](https://github.styleci.io).

---

For more information, click [here](https://github.styleci.io/analyses/8wKwbZ).
2019-03-02 22:58:37 +08:00

25 lines
574 B
PHP

<?php
namespace App\Http\Middleware;
use Illuminate\Support\Str;
class RedirectIfUrlEndsWithSlash
{
public function handle($request, \Closure $next)
{
if (substr($request->getRequestUri(), -1) == '/') {
$baseUrl = $request->getBaseUrl();
// Try to remove slash at the end of current url
$newUrl = substr($request->getRequestUri(), 0, -1);
if ($newUrl != $baseUrl) {
return redirect(Str::replaceLast($baseUrl, '', $newUrl));
}
}
return $next($request);
}
}