PHPackages                             barryvanveen/lastfm - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. barryvanveen/lastfm

ActiveLibrary[API Development](/categories/api)

barryvanveen/lastfm
===================

Last.fm API client for PHP 7+

2.0.0(3y ago)254.5k↓100%7MITPHPPHP ^8.0

Since Mar 13Pushed 3y ago2 watchersCompare

[ Source](https://github.com/barryvanveen/lastfm)[ Packagist](https://packagist.org/packages/barryvanveen/lastfm)[ Docs](https://github.com/barryvanveen/lastfm)[ RSS](/packages/barryvanveen-lastfm/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (5)Versions (11)Used By (0)

Last.fm API client for PHP 8
============================

[](#lastfm-api-client-for-php-8)

[![Latest Version on Packagist](https://camo.githubusercontent.com/7d54d6a9431f9fa5641e60533fa2f7adbd5dd8314b07ba683f6e630a36ca5bca/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f626172727976616e7665656e2f6c617374666d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/barryvanveen/lastfm)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/d4dcf0ec5e7250f4b0717c8e7b8fcb340e46400d84da2daa7aac2c413c2c93fb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f626172727976616e7665656e2f6c617374666d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/barryvanveen/lastfm)

- [API keys](#api-keys)
- [Installation](#installation)
- [Laravel installation](#laravel-installation)
- [Usage](#usage)
    - [Basic example](#basic-example)
    - [Laravel example](#laravel-example)
    - [All available methods](#all-available-methods)
    - [Filtering results](#filtering-results)
    - [Valid time periods](#valid-time-periods)
- [Official API docs](#official-api-docs)

API keys
--------

[](#api-keys)

You can create a last.fm API account at .

Installation
------------

[](#installation)

Via Composer

```
$ composer require barryvanveen/lastfm
```

Laravel installation
--------------------

[](#laravel-installation)

Add a LASTFM\_API\_KEY variable to your .env configuration. You could also publish the default configuration and alter it yourself:

```
php  artisan vendor:publish --provider="Barryvanveen\Lastfm\LastfmServiceProvider"
```

Update `config/app.php` by adding the LastfmServiceProvider:

```
'providers' => [
    ...
    Barryvanveen\Lastfm\LastfmServiceProvider::class,
];
```

If you are using Laravel 5.5 or higher, the service provider will be detected automagically by Laravel's [package discovery](https://laravel.com/docs/5.5/packages#package-discovery).

Tested against Laravel 5.\* but probably works in most versions because it is so simple. Please create an issue if it doesn't work for you.

Usage
-----

[](#usage)

### Basic example

[](#basic-example)

```
use Barryvanveen\Lastfm\Lastfm;
use GuzzleHttp\Client;

$lastfm = new Lastfm(new Client(), 'YourApiKey');

$albums = $lastfm->userTopAlbums('AnyUsername')->get();
```

### Laravel example

[](#laravel-example)

```
use Barryvanveen\Lastfm\Lastfm;

public function index(Lastfm $lastfm)
{
    $albums = $lastfm->userTopAlbums('AnyUsername')->get();

    return view('home', compact('albums'));
}
```

### All available methods

[](#all-available-methods)

```
// Get top albums for user
$albums = $lastfm->userTopAlbums('AnyUsername')->get();

// Get top artists for user
$artists = $lastfm->userTopArtists('AnyUsername')->get();

// Get recent tracks for user
$tracks = $lastfm->userRecentTracks('AnyUsername')->get();

// Get user info
$info = $lastfm->userInfo('AnyUsername')->get();

// Get track that user is now listening to, or FALSE
$trackOrFalse = $lastfm->nowListening('AnyUsername');

// Get the weekly top albums given a starting day
$albums = $lastfm->userWeeklyTopAlbums('AnyUsername', new \DateTime('2017-01-01'));

// Get the weekly top artists given a starting day
$artists = $lastfm->userWeeklyTopArtists('AnyUsername', new \DateTime('2017-01-01'));

// Get the weekly top tracks given a starting day
$tracks = $lastfm->userWeeklyTopTracks('AnyUsername', new \DateTime('2017-01-01'));
```

### Filtering results

[](#filtering-results)

```
// Define time period for results
$lastfm->userTopAlbums('AnyUsername')
       ->period(Barryvanveen\Lastfm\Constants::PERIOD_WEEK)
       ->get();

// Limit number of results
$lastfm->userTopAlbums('AnyUsername')
       ->limit(5)
       ->get();

// Retrieve paginated results
$lastfm->userTopAlbums('AnyUsername')
       ->limit(5)
       ->page(2)
       ->get();
```

### Valid time periods

[](#valid-time-periods)

```
// use these constants as an argument to ->period()
Barryvanveen\Lastfm\Constants::PERIOD_WEEK     = '7day';
Barryvanveen\Lastfm\Constants::PERIOD_MONTH    = '1month';
Barryvanveen\Lastfm\Constants::PERIOD_3_MONTHS = '3month';
Barryvanveen\Lastfm\Constants::PERIOD_6_MONTHS = '6month';
Barryvanveen\Lastfm\Constants::PERIOD_YEAR     = '12month';
Barryvanveen\Lastfm\Constants::PERIOD_OVERALL  = 'overall';
```

Official API docs
-----------------

[](#official-api-docs)

Read the official API documentation at .

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

Copy `phpunit.xml.dist` to `phpunit.xml`. Then run the tests using:

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Barry van Veen](https://github.com/barryvanveen)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

39

↑

LowBetter than 87% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity74

Established project with proven stability

 Bus Factor1

Top contributor holds 98.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~238 days

Recently: every ~433 days

Total

9

Last Release

1385d ago

Major Versions

1.2.1 → 2.0.02022-06-06

PHP version history (2 changes)1.0.0PHP &gt;=7.0

2.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/baf4ad1125e1706235b0cb4044df29e5bfaa67537a7de2e03ca0020b3bc631bc?d=identicon)[barryvanveen](/maintainers/barryvanveen)

---

Top Contributors

[![barryvanveen](https://avatars.githubusercontent.com/u/8548677?v=4)](https://github.com/barryvanveen "barryvanveen (61 commits)")[![Bruno7kp](https://avatars.githubusercontent.com/u/6254886?v=4)](https://github.com/Bruno7kp "Bruno7kp (1 commits)")

---

Tags

laravellaravel-packagelastfmlastfm-apiphpapiclientlaravelservice providerlaravel5PHP7last.fm

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/barryvanveen-lastfm/health.svg)

```
[![Health](https://phpackages.com/badges/barryvanveen-lastfm/health.svg)](https://phpackages.com/packages/barryvanveen-lastfm)
```

###  Alternatives

[openai-php/laravel

OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with the Open AI API

3.7k7.0M61](/packages/openai-php-laravel)[devio/pipedrive

Complete Pipedrive API client for PHP and/or Laravel

1691.8M](/packages/devio-pipedrive)[jubaer/zoom-laravel

A comprehensive Zoom integration package for Laravel, providing easy-to-use API functionality to interact with the Zoom platform using PHP.

57102.7k](/packages/jubaer-zoom-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
