mbsoft31/laravel-openalex
最新稳定版本:v1.0.0
Composer 安装命令:
composer require mbsoft31/laravel-openalex
包简介
A fluent, elegant, and modern wrapper for the OpenAlex API, built for Laravel.
README 文档
README
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();
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-09-21