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

20 lines
470 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
2016-10-16 18:16:15 +08:00
use App\Models\Player;
2019-04-24 13:10:03 +08:00
use Illuminate\Support\Arr;
2016-07-21 22:01:57 +08:00
2016-12-17 22:45:08 +08:00
class CheckPlayerExist
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
{
2019-04-24 13:10:03 +08:00
$pid = Arr::get($request->route()->parameters, 'pid') ?? $request->input('pid');
2020-01-12 17:14:23 +08:00
if (!$request->isMethod('get') && !is_null($pid) && is_null(Player::find($pid))) {
return json(trans('general.unexistent-player'), 1);
}
2020-01-12 17:14:23 +08:00
return $next($request);
2016-07-21 22:01:57 +08:00
}
}