blessing-skin-server/app/Http/Middleware/CheckPlayerExistMiddleware.php

27 lines
626 B
PHP
Raw Normal View History

2016-07-21 22:01:57 +08:00
<?php
2016-08-28 10:05:21 +08:00
namespace App\Http\Middleware;
2016-07-21 22:01:57 +08:00
use App\Models\PlayerModel;
2016-08-28 10:05:21 +08:00
class CheckPlayerExistMiddleware
2016-07-21 22:01:57 +08:00
{
2016-08-28 10:05:21 +08:00
public function handle($request, \Closure $next)
2016-07-21 22:01:57 +08:00
{
if (stripos($request->getUri(), '.json') != false) {
preg_match('/\/([^\/]*)\.json/', $request->getUri(), $matches);
} else {
preg_match('/\/([^\/]*)\.png/', $request->getUri(), $matches);
}
$player_name = urldecode($matches[1]);
2016-07-21 22:01:57 +08:00
if (PlayerModel::where('player_name', $player_name)->get()->isEmpty()) {
abort(404, '角色不存在');
2016-07-21 22:01:57 +08:00
}
2016-08-28 10:05:21 +08:00
return $next($request);
2016-07-21 22:01:57 +08:00
}
}