laravel-openalex maintained by mbsoft31
Description
A fluent, elegant, and modern wrapper for the OpenAlex API, built for Laravel.
Author
Last update
2025/09/21 17:42
(dev-main)
License
Downloads
1
Laravel OpenAlex API Wrapper
A fluent, elegant, and modern wrapper for the OpenAlex API, built for Laravel.
Installation
composer require mbsoft31/laravel-openalex
Next, publish the configuration file:
php artisan vendor:publish \--provider="Mbsoft\\OpenAlex\\OpenAlexServiceProvider" \--tag="config"
It is highly recommended to add your email to config/openalex.php.
Usage
Basic Queries
use Mbsoft\\OpenAlex\\Facades\\OpenAlex;
// Find a work by its OpenAlex ID
$work = OpenAlex::works()->find('W2741809807');
// Find an author by their ORCID
$author = OpenAlex::authors()->findByOrcid('0000-0002-1825-0097');
// Get recent, highly-cited works about AI from a specific institution
$works = OpenAlex::works()
->whereInstitutionRor('042nb2s44') // MIT
->where('publication_year', '>2024')
->search('artificial intelligence')
->sortBy('cited_by_count')
->get();
Automatic Pagination
The paginate method returns a standard Laravel LengthAwarePaginator instance.
$paginatedWorks = OpenAlex::works()
->whereHas('concepts.id', 'C15744967') // AI
->paginate(perPage: 50, page: 2);
echo "Total AI papers: " . $paginatedWorks->total();
Cursors for Large Datasets
Use cursor() to iterate over a large result set without consuming much memory. It fetches pages on-demand in the background.
$allWorksFromJournal = OpenAlex::works()
->where('primary_location.source.id', 'S4306520188')
->cursor();
foreach ($allWorksFromJournal as $work) {
// Process millions of records safely
}
Caching
Drastically improve performance by caching API responses.
// Cache for 10 minutes
$works = OpenAlex::works()->where('publication_year', 2025)->cacheFor(600)->get();
// Cache forever
$source = OpenAlex::sources()->find('S139121223')->cacheForever()->get();
DTO Utilities
The returned Data Transfer Objects are equipped with helpful methods.
$work = OpenAlex::works()->find('W2741809807');
// Get plain text abstract
$abstract = $work->getAbstract();
// Get BibTeX citation
$bibtex = $work->toBibTeX();