binalogue/nova-spotify-playlist-field

A Spotify playlist field to use in your Laravel Nova apps.

dev-master 2019-03-22 14:36 UTC

This package is auto-updated.

Last update: 2024-04-23 02:11:03 UTC


README

Latest Version on Packagist Build Status Quality Score Total Downloads

This Nova package adds a Spotify playlist field. Under the hood it uses the binalogue/laravel-spotify-wrapper and binalogue/nova-spotify-auth-tool packages.

You can add tracks from the Spotify Web API to your database.

Laravel Nova Spotify Playlist Field

Installation

First, you must install binalogue/laravel-spotify-wrapper and binalogue/nova-spotify-auth-tool into your Laravel app.

Next, you can install this package via Composer:

composer require binalogue/nova-spotify-playlist-field

Use

Register the field in your resource's fields method:

/**
 * Get the fields displayed by the resource.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return array
 */
public function fields(Request $request)
{
    return [
        ...
        \Binalogue\SpotifyPlaylistField\SpotifyPlaylistField::make('Name')
            ->spotifyAccessToken()
            ->optionalParameters([
                'id' => 'spotify_id',
                'artist_name' => 'artist',
                'duration_ms' => 'duration_ms',
                'popularity' => 'popularity',
                'preview_url' => 'preview_url',',
            ]),
        ...
    ];
}

You must use the following methods:

  • spotifyAccessToken: to request a Spotify access token from the refresh token stored in the database (see binalogue/nova-spotify-auth-tool).
  • optionalParameters: a key-value array that indicates which track attributes you would like to store (keys), and the column name in your database where they may be stored (values).

List of track attributes:

  • id: The Spotify ID for the track.
  • name: The name of the track.
  • artist_id: The Spotify ID for the artist.
  • artist_name: The name of the artist
  • duration_ms: The track length in milliseconds.
  • popularity: The popularity of the track. The value will be between 0 and 100, with 100 being the most popular.
  • preview_url: A link to a 30 second preview (MP3 format) of the track. Can be null.
  • first_letter: The first letter of the track (e.g. in Tail Lights will be T).

More info in the Spotify Web API.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Credits

License

The MIT License (MIT). Please see License File for more information.