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).
25 lines
574 B
PHP
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);
|
|
}
|
|
}
|