rename middlewares
This commit is contained in:
parent
372be47ac8
commit
8677cd9376
@ -25,13 +25,12 @@ class Kernel extends HttpKernel
|
||||
protected $middlewareGroups = [
|
||||
'web' => [
|
||||
\App\Http\Middleware\EncryptCookies::class,
|
||||
\App\Http\Middleware\RemoveSlashMiddleware::class,
|
||||
\App\Http\Middleware\RedirectIfUrlEndsWithSlash::class,
|
||||
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
|
||||
\Illuminate\Session\Middleware\StartSession::class,
|
||||
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
|
||||
\App\Http\Middleware\Internationalization::class,
|
||||
\App\Http\Middleware\SaveOptionRepository::class,
|
||||
//\App\Http\Middleware\VerifyCsrfToken::class,
|
||||
],
|
||||
|
||||
'static' => [
|
||||
@ -49,7 +48,7 @@ class Kernel extends HttpKernel
|
||||
protected $routeMiddleware = [
|
||||
'auth' => \App\Http\Middleware\CheckAuthenticated::class,
|
||||
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
|
||||
'admin' => \App\Http\Middleware\CheckAdminMiddleware::class,
|
||||
'player' => \App\Http\Middleware\CheckPlayerExistMiddleware::class
|
||||
'admin' => \App\Http\Middleware\CheckAdministrator::class,
|
||||
'player' => \App\Http\Middleware\CheckPlayerExist::class
|
||||
];
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
class CheckAdminMiddleware
|
||||
class CheckAdministrator
|
||||
{
|
||||
public function handle($request, \Closure $next)
|
||||
{
|
@ -6,7 +6,7 @@ use Event;
|
||||
use App\Models\Player;
|
||||
use App\Events\CheckPlayerExists;
|
||||
|
||||
class CheckPlayerExistMiddleware
|
||||
class CheckPlayerExist
|
||||
{
|
||||
public function handle($request, \Closure $next)
|
||||
{
|
||||
@ -27,7 +27,7 @@ class CheckPlayerExistMiddleware
|
||||
if (!Player::where('player_name', $player_name)->get()->isEmpty())
|
||||
return $next($request);
|
||||
|
||||
if (option('return_200_when_notfound') == "1") {
|
||||
if (option('return_200_when_notfound')) {
|
||||
return json([
|
||||
'player_name' => $player_name,
|
||||
'errno' => 404,
|
24
app/Http/Middleware/RedirectIfUrlEndsWithSlash.php
Normal file
24
app/Http/Middleware/RedirectIfUrlEndsWithSlash.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class RemoveSlashMiddleware
|
||||
{
|
||||
public function handle($request, \Closure $next)
|
||||
{
|
||||
if (substr($request->getRequestUri(), -1) == "/") {
|
||||
$base_dir = $request->getBaseUrl();
|
||||
// try to remove slash at the end of current url
|
||||
$new_url = substr($request->getRequestUri(), 0, -1);
|
||||
|
||||
if ($new_url != $base_dir) {
|
||||
return redirect(Str::replaceLast($base_dir, '', $new_url));
|
||||
}
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user