love_php/app/Http/Middleware/CheckFriendRequest.php
2026-04-02 09:20:51 +08:00

34 lines
898 B
PHP

<?php
namespace App\Http\Middleware;
use Closure;
use App\Services\UserService;
use App\Http\Response\ResponseJson;
class CheckFriendRequest
{
use ResponseJson;
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
try {
$user = auth()->user();
$is_real_approved = $user->is_real_approved;
$other_user = $request->user?:null;
if ($other_user&&!$is_real_approved) {
$count = $user->chatMessageCountWithUser($other_user->id);
if ($count >= 3&&$user->type=='signle') return $this->failv2('未真人认证聊天限制');
}
} catch (\Exception $e) {
$this->getError($e);
}
return $next($request);
}
}