mgoigfer/nova-spotify-track-field

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

Installs: 4

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Language:JavaScript

Type:package

0.2.0 2018-11-26 23:51 UTC

This package is auto-updated.

Last update: 2024-10-27 14:05:56 UTC


README

Latest Version on Packagist Build Status Quality Score Total Downloads

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

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

Laravel Nova Spotify Track Field

Installation

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

Next, you can install this package via Composer:

composer require mgoigfer/nova-spotify-track-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 [
        ...
        \Mgoigfer\SpotifyTrackField\SpotifyTrackField::make('Name')
            ->spotifyAccessToken()
            ->extraAttributes([
                '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 mgoigfer/nova-spotify-auth-tool).
  • extraAttributes: 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.