Revived API POST /captcha/{captcha_uuid}.
Receiving captcha information for validation.
This commit is contained in:
		@@ -5,6 +5,7 @@ namespace App\Repositories;
 | 
			
		||||
use App\Enums\CaptchaLogType;
 | 
			
		||||
use App\Models\CaptchaLog;
 | 
			
		||||
use Illuminate\Database\Eloquent\Builder;
 | 
			
		||||
use Illuminate\Database\Eloquent\Collection;
 | 
			
		||||
 | 
			
		||||
final class CaptchaLogRepository
 | 
			
		||||
{
 | 
			
		||||
@@ -12,9 +13,23 @@ final class CaptchaLogRepository
 | 
			
		||||
    {
 | 
			
		||||
        return CaptchaLog::query()
 | 
			
		||||
            ->when($captchaId, function (Builder $query, int $captchaId) {
 | 
			
		||||
                $query->where('id', $captchaId);
 | 
			
		||||
                $query->where('captcha_id', $captchaId);
 | 
			
		||||
            })
 | 
			
		||||
            ->where('type', '=', $type)
 | 
			
		||||
            ->count();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getCaptchaLogsByTypes(array $types, ?int $captchaId = null, ?int $limit = null): Collection
 | 
			
		||||
    {
 | 
			
		||||
        return CaptchaLog::query()
 | 
			
		||||
            ->when($captchaId, function (Builder $query, int $captchaId) {
 | 
			
		||||
                $query->where('captcha_id', $captchaId);
 | 
			
		||||
            })
 | 
			
		||||
            ->when($limit, function (Builder $query, int $limit) {
 | 
			
		||||
                $query->limit($limit);
 | 
			
		||||
            })
 | 
			
		||||
            ->whereIn('type', $types)
 | 
			
		||||
            ->latest()
 | 
			
		||||
            ->get();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -3,6 +3,7 @@
 | 
			
		||||
namespace App\Repositories;
 | 
			
		||||
 | 
			
		||||
use App\Models\Captcha;
 | 
			
		||||
use App\Models\CaptchaToken;
 | 
			
		||||
 | 
			
		||||
final class CaptchaRepository
 | 
			
		||||
{
 | 
			
		||||
@@ -10,4 +11,9 @@ final class CaptchaRepository
 | 
			
		||||
    {
 | 
			
		||||
        return Captcha::query()->where('id', $id)->first();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getCaptchaByUuid(CaptchaToken $captchaToken, string $uuid): ?Captcha
 | 
			
		||||
    {
 | 
			
		||||
        return $captchaToken->captchas()->where('uuid', $uuid)->first();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -41,4 +41,9 @@ final readonly class CaptchaTokenRepository
 | 
			
		||||
    {
 | 
			
		||||
        return CaptchaToken::query()->where('public_token', '=', $token)->first();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function getCaptchaTokenByPrivateToken(string $token): ?CaptchaToken
 | 
			
		||||
    {
 | 
			
		||||
        return CaptchaToken::query()->where('private_token', '=', $token)->first();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user