app\models\Song::updateInfo PHP Méthode

updateInfo() public static méthode

Update song info.
public static updateInfo ( array $ids, array $data ) : array
$ids array
$data array The data array, with these supported fields: - title - artistName - albumName - lyrics All of these are optional, in which case the info will not be changed (except for lyrics, which will be emptied).
Résultat array
    public static function updateInfo($ids, $data)
    {
        /*
         * An array of the updated songs.
         *
         * @var array
         */
        $updatedSongs = [];
        $ids = (array) $ids;
        // If we're updating only one song, take into account the title, lyrics, and track number.
        $single = count($ids) === 1;
        foreach ($ids as $id) {
            if (!($song = self::with('album', 'album.artist')->find($id))) {
                continue;
            }
            $updatedSongs[] = $song->updateSingle($single ? trim($data['title']) : $song->title, trim($data['albumName'] ?: $song->album->name), trim($data['artistName']) ?: $song->artist->name, $single ? trim($data['lyrics']) : $song->lyrics, $single ? (int) $data['track'] : $song->track, (int) $data['compilationState']);
        }
        // Our library may have been changed. Broadcast an event to tidy it up if need be.
        if ($updatedSongs) {
            event(new LibraryChanged());
        }
        return $updatedSongs;
    }

Usage Example

Exemple #1
0
 /**
  * Update songs info.
  *
  * @param SongUpdateRequest $request
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function update(SongUpdateRequest $request)
 {
     return response()->json(Song::updateInfo($request->songs, $request->data));
 }