PHPackages                             rennokki/larafy - 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. rennokki/larafy

AbandonedArchivedLibrary[API Development](/categories/api)

rennokki/larafy
===============

Larafy is a Laravel API wrapper for Spotify.

1.0.3(7y ago)5039.6k9[1 issues](https://github.com/rennokki/larafy/issues)MITPHP

Since Aug 15Pushed 6y ago3 watchersCompare

[ Source](https://github.com/rennokki/larafy)[ Packagist](https://packagist.org/packages/rennokki/larafy)[ Docs](https://github.com/rennokki/larafy)[ RSS](/packages/rennokki-larafy/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (4)Dependencies (4)Versions (5)Used By (0)

[![Build Status](https://camo.githubusercontent.com/fa8f0fa7150e71ab646acc3190ef07cbf0cb2227ac82d219bd1a732c5f17477c/68747470733a2f2f7472617669732d63692e6f72672f72656e6e6f6b6b692f6c61726166792e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/rennokki/larafy)[![codecov](https://camo.githubusercontent.com/c8e7b8d28b7989db400c2f6f9567a9d7467df93cc5a5824328141a922804d3c0/68747470733a2f2f636f6465636f762e696f2f67682f72656e6e6f6b6b692f6c61726166792f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/rennokki/larafy/branch/master)[![StyleCI](https://camo.githubusercontent.com/51acab857d8b8324efcdcd9ab99defe60ac90e6e051fd5b406d19fc2748a758a/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3134343637373734392f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/143601238)[![Latest Stable Version](https://camo.githubusercontent.com/08a3b06e8817e67707d41aec1cc641cf0846b252b053059629d44fe347f94aa3/68747470733a2f2f706f7365722e707567782e6f72672f72656e6e6f6b6b692f6c61726166792f762f737461626c65)](https://packagist.org/packages/rennokki/larafy)[![Total Downloads](https://camo.githubusercontent.com/a5875e7cee7ff448da9d59b666ccc06e834e61f4a9c5f5c84f3ad34e3c9c3c5d/68747470733a2f2f706f7365722e707567782e6f72672f72656e6e6f6b6b692f6c61726166792f646f776e6c6f616473)](https://packagist.org/packages/rennokki/larafy)[![Monthly Downloads](https://camo.githubusercontent.com/fe5f9081581575bd3af6592dd4f101c5a310d554313b46622d20d2c76aba23be/68747470733a2f2f706f7365722e707567782e6f72672f72656e6e6f6b6b692f6c61726166792f642f6d6f6e74686c79)](https://packagist.org/packages/rennokki/larafy)[![License](https://camo.githubusercontent.com/1315d708b91f67f2e94510087ece47fb8c6b10a3d1f89a8fa83cb126ef55c42f/68747470733a2f2f706f7365722e707567782e6f72672f72656e6e6f6b6b692f6c61726166792f6c6963656e7365)](https://packagist.org/packages/rennokki/larafy)

[![PayPal](https://camo.githubusercontent.com/e3d021da65162fda975bd58ef4a4d80bdd03d6e94aa1b321d179e6b4c1aff357/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f50617950616c2d646f6e6174652d626c75652e737667)](https://paypal.me/rennokki)

This package is no longer maintained!
=====================================

[](#this-package-is-no-longer-maintained)

Larafy
======

[](#larafy)

Larafy is a PHP API Wrapper for Spotify API. This wrapper is more oriented over Client Credentials authenticated endpoints and provides great interface and and eloquent way to search for tracks, seed genres or simply just provide custom tracks/albums listings for your users.

Installation
============

[](#installation)

Install the package:

```
$ composer require rennokki/larafy
```

If your Laravel version does not support package discovery, add this line in the `providers` array in your `config/app.php` file:

```
Rennokki\Larafy\LarafyServiceProvider::class,
```

Setting up the API
==================

[](#setting-up-the-api)

For this, you will need an APP ID and an APP SECRET from your Spotify API Dashboard.

For a cleaner approach, add the following to your `config/services.php` file:

```
'spotify' => [
    'client_id' => env('SPOTIFY_KEY'),
    'client_secret' => env('SPOTIFY_SECRET'),
    'redirect' => env('SPOTIFY_REDIRECT_URI')
],
```

To use the API, you just pass no construct parameters to `Rennokki\Larafy\Larafy`:

```
$api = new Larafy();
```

If you want to change the credentials on-demand, you can do so by declaring a new API instance with your App ID and your App Secret:

```
use Rennokki\Larafy\Larafy;

$api = new Larafy('your_app_id_here', 'your_app_secret_here');
```

Showcase
========

[](#showcase)

All requests throw exceptions, either if the data is invalid, either if the request is... bad. To do so, there are provided two exceptions that can be caught:

- `\Rennokki\Larafy\Exceptions\SpotifyAPIException` - thrown when the API is authenticated correctly, but the data passed is invalid.
- `\Rennokki\Larafy\Exceptions\SpotifyAuthorizationException` - thrown when the API can't authenticate using credentials provided.

```
try {
    $api->searchArtists('Lana del Rey');
} catch(\Rennokki\Larafy\Exceptions\SpotifyAuthorizationException $e) {
    // invalid ID & Secret provided
    $e->getAPIResponse(); // Get the JSON API response.
}
```

```
try {
    $api->searchArtists('Lana del Rey', -30, -40);
} catch(\Rennokki\Larafy\Exceptions\SpotifyAPIException $e) {
    // invalid data sent
    $e->getAPIResponse(); // Get the JSON API response.
}
```

Since Spotify is related to music, it has some certain restrictions over markets and locales. This happens because, for example, some albums that are available in a country may not be available in other countries, such as the `AC/DC`'s `The Razor Edge` album, that has different versions across countries like `Austrialia` or the `US`.

To help give a better search over the market and, respectively, locales, use the `setMarket()` and `setLocale()` methods within the API instance. These are by default set to `US` and `en_US`. These are optional.

You can chain them:

```
$api->setMarket('RO')->setLocale('ro_RO');
```

Or set them on demand:

```
$api->setMarket('ES');
...
$api->setLocale('es_ES');
```

Some requests need an `offset` and a `limit`, which are optional and set by default to `0` and respectively `10`. The limit is how many results can be shown in the request and the offset indicates how many results to offset, starting from the first. See the next examples on how you can use this feature.

```
$limit = 15;
$offset = 5;

$api->searchAlbums('Master of Puppets', $limit, $offset); // limit 15 with 5 offset.
```

When retrieving multiple data, you can either pass an array or a string with comma-separated values:

```
$api->getAlbums(['album_id_1', 'album_id_2', ...]);
$api->getAlbums('album_id_1,album_id_2,...');
```

When issuing requests on endpoints that might return more data, usually this is done by accessing the `items` property:

```
$masterOfPuppets = $api->searchAlbums('Master of Puppets');
$masterOfPuppets->items; // this is the array with all results
```

For the `getArtistAlbums()` method, there is an option to search artist's albums based on the fact it is a single or the artist appears on that album. To do so, there is applied the same rule as the comma-separated values or array method.

```
$api->getArtistAlbums('artist_id', $limit, $offset, ['single', 'appears_on']);
$api->getArtistAlbums('artist_id', $limit, $offset, ['single']);
$api->getArtistAlbums('artist_id', $limit, $offset, 'single');
$api->getArtistAlbums('artist_id', $limit, $offset, 'single,appears_on');
```

API Usage
=========

[](#api-usage)

Recommendations
---------------

[](#recommendations)

Recommendations allows you to query up the Spotify API into getting something personalized. The [Recommendations endpoint](https://developer.spotify.com/documentation/web-api/reference/browse/get-recommendations) allows you to do that by seeding tracks, genres and artists and a bunch of adjustable properties such as energy, key and danceability to get personalized tracks for your users.

Before getting into it, make sure you are familiar with the [Recommendations Endpoint](https://developer.spotify.com/documentation/web-api/reference/browse/get-recommendations).

Each track has its own properties such as key, danceability, energy or loudness. To do so, the `\Rennokki\Larafy\LarafySeed` class helps you build your seed easier. Let's start with an example:

```
$seed = (new LarafySeed)
    ->setGenres(['death-metal', 'hard-rock', 'black-metal'])
    ->setTargetValence(90.3)
    ->setSpeechiness(60.0, 90.0)
    ->setLoudness(80.0, 100.0)
    ->setLiveness(80.0, 100.0);

$tracks = $api->getRecommendations($seed, $limit);
foreach ($tracks->items as $track) {
    ...
}
```

In the previous example, we just have searched tracks from Death Metal, Hard Rock and Black Metal whose valence (the positivity; the higher, the more positive) is around `90.3`, and then we set some ranges for speechiness (the higher, the less musical it is: podcasts), loudness and liveness (the higher, the more chances it is a live performance).

To get the available seeds, you may use the `$api->getGenreSeeds()` to get a list of possible values for the `setGenres()` method.

There is a difference between:

- `set{property}($min, $max)`
- `setTarget{property}($value)`.

When setting up a range, it might vary between two values. When setting up a target value, it just gets around it as much as possible. [Read more about each seed here](https://developer.spotify.com/documentation/web-api/reference/browse/get-recommendations)

To add artists, tracks or genres, you may use:

```
$seed->addArtist('artist_id');
$seed->addArtists(['artist_id_1', 'artist_id_2', ...']);
$seed->addArtists('artist_id_1,artist_id_2,...');
$seed->setArtists(['artist_id_1', 'artist_id_2', ...']); // overwrites
$seed->setArtists('artist_id_1,artist_id_2,...'); // overwrites

$seed->addTrack('track_id');
$seed->addTracks(['track_id_1', 'track_id_2', ...']);
$seed->addTracks('track_id_1,track_id_2,...');
$seed->setTracks(['track_id_1', 'track_id_2', ...']); // overwrites
$seed->setTracks('track_id_1,track_id_2,...'); // overwrites

$seed->addGenre('genre');
$seed->addGenres(['genre1', 'genre2', ...']);
$seed->addGenres('genre1,genre2,...');
$seed->setGenres(['genre1', 'genre2', ...']); // overwrites
$seed->setGenres('genre1,genre2,...'); // overwrites
```

For tunable properties of the songs, you can use the following methods:

```
$seed->setAcousticness($min, $max); // float
$seed->setTargetAcousticness($target); // float

$seed->setDanceability($min, $max); // float
$seed->setTargetDanceability($target); // float

$seed->setEnergy($min, $max); // float
$seed->setTargetEnergy($target); // float

$seed->setInstrumentalness($min, $max); // float
$seed->setTargetInstrumentalness($target); // float

$seed->setKeys($min, $max); // int
$seed->setTargetKey($target); // int

$seed->setLiveness($min, $max); // float
$seed->setTargetLiveness($target); // float

$seed->setLoudness($min, $max); // float
$seed->setTargetLoudness($target); // float

$seed->setMode($min, $max); // int
$seed->setTargetMode($target); // int

$seed->setPopularity($min, $max); // float
$seed->setTargetPopularity($target); // float

$seed->setSpeechiness($min, $max); // float
$seed->setTargetSpeechiness($target); // float

$seed->setTempo($min, $max); // int
$seed->setTargetTempo($target); // int

$seed->setTimeSignature($min, $max); // int
$seed->setTargetTimeSignature($target); // int

$seed->setValence($min, $max); // float
$seed->setTargetValence($target); // float

$seed->setDuration($min, $max); // int, in seconds
$seed->setTargetDuration($target); // int, in seconds
```

**Note: While building your seed, you can chain how many properties you want.**

### Albums

[](#albums)

[API Reference on Albums](https://developer.spotify.com/console/albums)

```
// Search for albums.
$api->searchAlbums('Master of Puppets', $limit, $offset);

// Get an album using ID.
$api->getAlbum('album_id');

// Get more albums at once based on IDs.
$api->getAlbums(['id1', 'id2', ...]);
$api->getAlbums('id1,id2,...');

// Get album's tracks.
$api->getAlbumTracks('album_id', $limit, $offset);
```

### Tracks

[](#tracks)

[API Reference on Tracks](https://developer.spotify.com/console/tracks)

```
// Search for tracks.
$api->searchTracks('Fade to Black', $limit, $offset);

// Get a track using ID.
$api->getTrack('track_id');

// Get more tracks at once based on IDs.
$api->getTracks(['id1', 'id2', ...]);
$api->getTracks('id1,id2,...');
```

### Artists

[](#artists)

[API Reference on Artists](https://developer.spotify.com/console/artists)

```
// Search for artists.
$api->searchArtists('Metallica', $limit, $offset);

// Get an artist using ID.
$api->getArtist('artist_id');

// Get more artists at once based on IDs.
$api->getArtists(['id1', 'id2', ...]);
$api->getArtists('id1,id2,...');

// Get artist's albums.
$api->getArtistAlbums('artist_id', $limit, $offset, ['single', 'appears_on']);

// Get artist's top tracks.
$api->getArtistTopTracks('artist_id');

// Get artist's related artists.
$api->getArtistRelatedArtists('artist_id');
```

### Playlists

[](#playlists)

[API Reference on Playlists](https://developer.spotify.com/console/playlists)

```
// Search for playlists.
$api->searchPlaylists('This Is Metallica', $limit, $offset);

// Get a playlist using ID.
$api->getPlaylist('playlist_id');

// Get playlist's albums.
$api->getPlaylistTracks('playlist_id', $limit, $offset);

// Get featured playlists from a specific time.
$api->getFeaturedPlaylists(Carbon::now(), $limit, $offset);
$api->getFeaturedPlaylists('2018-05-19 00:00:00', $limit, $offset);
```

### Browse

[](#browse)

[API Reference on Browse](https://developer.spotify.com/console/browse)

```
// Get genre seeds.
$api->getGenreSeeds();

// Get all the Browse categories.
$api->getBrowseCategories($limit, $offset);

// Get details about one of the Browse's category.
$api->getBrowseCategory('mood');

// Get playlists from a Browse category.
$api->getCategoryPlaylists('mood', $limit, $offset);

// Get new albums releases.
$api->getNewReleases($limit, $offset);
```

###  Health Score

37

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~56 days

Total

4

Last Release

2656d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/21983456?v=4)[rennokki](/maintainers/rennokki)[@rennokki](https://github.com/rennokki)

---

Top Contributors

[![rennokki](https://avatars.githubusercontent.com/u/21983456?v=4)](https://github.com/rennokki "rennokki (27 commits)")

---

Tags

albumalbumsapigenrelaravelmusicpackagepackagesphpplayerrecommendationrecommendationsseedsongsongsspotifytracktrackswrapperapilaravelwrapperAlbumspotifymusictracktracksplaylistsalbumsplaylistsongs

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/rennokki-larafy/health.svg)

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

###  Alternatives

[aerni/laravel-spotify

A Laravel wrapper for the Spotify Web API

209145.6k](/packages/aerni-laravel-spotify)[dariusiii/tmdb-laravel

Laravel Package for TMDB ( The Movie Database ) API. Provides easy access to the wtfzdotnet/php-tmdb-api library.

1821.1k](/packages/dariusiii-tmdb-laravel)[lasserafn/laravel-economic

Economic REST wrapper for Laravel

1118.5k](/packages/lasserafn-laravel-economic)[lasserafn/php-dinero

Dinero REST wrapper for PHP

115.2k](/packages/lasserafn-php-dinero)

PHPackages © 2026

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