PHP code example of mbsoft31 / laravel-openalex

1. Go to this page and download the library: Download mbsoft31/laravel-openalex library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mbsoft31 / laravel-openalex example snippets


    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();

$paginatedWorks = OpenAlex::works()  
    ->whereHas('concepts.id', 'C15744967') // AI  
    ->paginate(perPage: 50, page: 2);

echo "Total AI papers: " . $paginatedWorks->total();

$allWorksFromJournal = OpenAlex::works()  
    ->where('primary_location.source.id', 'S4306520188')  
    ->cursor();

foreach ($allWorksFromJournal as $work) {  
    // Process millions of records safely  
}

// Cache for 10 minutes  
$works = OpenAlex::works()->where('publication_year', 2025)->cacheFor(600)->get();

// Cache forever  
$source = OpenAlex::sources()->find('S139121223')->cacheForever()->get();

$work = OpenAlex::works()->find('W2741809807');

// Get plain text abstract  
$abstract = $work->getAbstract();

// Get BibTeX citation  
$bibtex = $work->toBibTeX();  
bash
php artisan vendor:publish \--provider="Mbsoft\\OpenAlex\\OpenAlexServiceProvider" \--tag="config"