Skip to content

Commit

Permalink
Use "request" where "response" is intended in docs (#3027)
Browse files Browse the repository at this point in the history
This change corrects the documentation where the word "response" was used, but "request" was meant.
  • Loading branch information
euoia authored Sep 7, 2022
1 parent c228720 commit ce5cd34
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ The content of that request key will be an array. For each file uploaded that ar
- `uuid`: the UUID of a `Media` model. For newly uploaded files that have not been associated to a model yet, the `Media` model will be associated with a `TemporaryUpload` model
- `order`: the order in which this item should be stored in a media collection.

## Validating responses
## Validating requests

Even though the upload components do some validation of their own, we highly recommend always validating responses on the server as well.
Even though the upload components do some client-side validation, we highly recommend always validating requests on the server as well.

You should handle validation in a form request. On the form request you should use the `Spatie\MediaLibraryPro\Rules\Concerns\ValidatesMedia` trait. This will give you access to the `validateSingleMedia` and `validateMultipleMedia` methods.

Expand Down Expand Up @@ -257,13 +257,13 @@ class StoreLivewireCollectionCustomPropertyRequest extends FormRequest
}
```

## Processing responses
## Processing requests

After you've validated the response, you should persist the changes to the media library. The media library provides two methods for that: `syncFromMediaLibraryRequest` and `addFromMediaLibraryRequest`. Both these methods are available on all [models that handle media](/docs/laravel-medialibrary/v10/basic-usage/preparing-your-model). Either way call the method `toMediaCollection` to update your media-model in the database. This will also ensure that temporary uploads are converted to the appropriate model.
After you've validated the request, you should persist the changes to the media library. The media library provides two methods for that: `syncFromMediaLibraryRequest` and `addFromMediaLibraryRequest`. Both these methods are available on all [models that handle media](/docs/laravel-medialibrary/v10/basic-usage/preparing-your-model). Either way call the method `toMediaCollection` to update your media-model in the database. This will also ensure that temporary uploads are converted to the appropriate model.

### `addFromMediaLibraryRequest`

This method will add all media whose `uuid` is in the response to a media collection of a model. Existing media associated on the model will remain untouched.
This method will add all media whose `uuid` is in the request to a media collection of a model. Existing media associated on the model will remain untouched.

You should probably use this method when only accepting new uploads.

Expand Down

0 comments on commit ce5cd34

Please sign in to comment.