Looking to hire Laravel developers? Try LaraJobs

laravel-ahrefs maintained by jeffersongoncalves

Description
A lightweight Ahrefs API v3 client for Laravel — domain rating, backlinks, referring domains, organic keywords, top pages, and keyword research.
Last update
2026/09/06 02:50 (dev-master)
License
Links
Downloads
1

Comments
comments powered by Disqus

Laravel Ahrefs

Laravel Ahrefs

Tests PHPStan Code Style Latest Version on Packagist Total Downloads License

A lightweight Ahrefs API v3 client for Laravel. It wraps the Site Explorer and Keywords Explorer endpoints behind a small Ahrefs client/facade, threads your Bearer token, and returns the decoded JSON body — no DTOs, no response wrappers.

Features

  • Domain RatingdomainRating()
  • Backlinksbacklinks()
  • Referring domainsrefDomains()
  • Organic keywordsorganicKeywords()
  • Top pagestopPages()
  • Keyword overviewkeywordOverview()
  • Keyword suggestionskeywordSuggestions()
  • SERP overviewserpOverview()
  • A non-2xx response throws Illuminate\Http\Client\RequestException
  • Optional mode/country/limit params are omitted from the query when left null

Installation

composer require jeffersongoncalves/laravel-ahrefs

Optionally publish the config file:

php artisan vendor:publish --tag="ahrefs-config"

Configuration

Add to your .env:

AHREFS_API_KEY=your-ahrefs-api-token

Generate a token at https://app.ahrefs.com/api/keys.

Config Options

// config/ahrefs.php
return [
    'token' => env('AHREFS_API_KEY'),
    'base_url' => env('AHREFS_BASE_URL', 'https://api.ahrefs.com/v3'),
];

When ahrefs.token is null the client falls back to config('services.ahrefs.token').

Usage

Via the facade:

use JeffersonGoncalves\Ahrefs\Facades\Ahrefs;

Ahrefs::domainRating('example.com');

Ahrefs::backlinks('example.com', mode: 'subdomains', limit: 50);

Ahrefs::refDomains('example.com', mode: 'domain', limit: 100);

Ahrefs::organicKeywords('example.com', mode: 'exact', country: 'us', limit: 20);

Ahrefs::topPages('example.com', mode: 'domain', country: 'br', limit: 10);

Ahrefs::keywordOverview(['laravel', 'php'], country: 'us');
// or a single keyword / comma-separated string
Ahrefs::keywordOverview('laravel', country: 'us');

Ahrefs::keywordSuggestions('laravel', country: 'us', limit: 25);

Ahrefs::serpOverview('laravel', country: 'us');

Or inject/resolve the underlying client:

use JeffersonGoncalves\Ahrefs\Ahrefs;

$ahrefs = app(Ahrefs::class);
$ahrefs->domainRating('example.com');

mode values

domain (default), subdomains, prefix, exact — accepted by backlinks(), refDomains(), organicKeywords(), and topPages().

Error handling

use Illuminate\Http\Client\RequestException;

try {
    $rating = Ahrefs::domainRating('example.com');
} catch (RequestException $e) {
    // $e->response->status(), $e->response->json(), ...
}

Testing

composer test

Static Analysis

composer analyse

Code Formatting

composer format

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.