/**
  * Reorder media-records.
  *
  * @param $orderArray
  * @param MediaLibraryModelInterface $model
  */
 public function order($orderArray, MediaLibraryModelInterface $model)
 {
     $orderCounter = 0;
     foreach ($orderArray as $id => $order) {
         $media = Media::findOrFail($id);
         if ($media->content_type == get_class($model) && $media->content_id == $model->id) {
             $media->order_column = $orderCounter++;
             $media->save();
         }
     }
 }
 /**
  * Update a media collection by deleting and inserting again with new values.
  *
  * @param array  $newMediaArray
  * @param string $collectionName
  *
  * @throws Exception
  */
 public function updateMedia(array $newMediaArray, $collectionName)
 {
     $this->removeMediaItemsNotPresentInArray($newMediaArray, $collectionName);
     $orderCounter = 0;
     foreach ($newMediaArray as $newMediaItem) {
         $currentMedia = Media::findOrFail($newMediaItem['id']);
         if ($currentMedia->collection_name != $collectionName) {
             throw new Exception('Media id: ' . $currentMedia->id . ' error: Updating the wrong collection. Expected: "' . $collectionName . '" - got: "' . $currentMedia->collection_name);
         }
         if (array_key_exists('name', $newMediaItem)) {
             $currentMedia->name = $newMediaItem['name'];
         }
         $currentMedia->order_column = $orderCounter++;
         $currentMedia->temp = 0;
         $currentMedia->save();
     }
 }