2019-03-22 21:40:12 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
|
|
|
use Closure;
|
|
|
|
|
|
|
|
class RequireBindPlayer
|
|
|
|
{
|
|
|
|
public function handle($request, Closure $next)
|
|
|
|
{
|
2019-12-14 11:10:37 +08:00
|
|
|
if (!option('single_player', false)) {
|
2019-03-22 21:40:12 +08:00
|
|
|
if ($request->is('user/player/bind')) {
|
|
|
|
return redirect('/user');
|
|
|
|
} else {
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This allows us to fetch players list.
|
|
|
|
if ($request->is('user/player/list')) {
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
|
|
|
|
$count = auth()->user()->players()->count();
|
|
|
|
|
|
|
|
if ($request->is('user/player/bind')) {
|
|
|
|
if ($count == 1) {
|
|
|
|
return redirect('/user');
|
|
|
|
} else {
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($count == 1) {
|
|
|
|
return $next($request);
|
|
|
|
} else {
|
|
|
|
return redirect('user/player/bind');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|