Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add explanation for processing responses #2850

Merged
merged 1 commit into from
Mar 22, 2022
Merged

Add explanation for processing responses #2850

merged 1 commit into from
Mar 22, 2022

Conversation

SahinU88
Copy link
Contributor

Not sure if I missed it somewhere else, but I guess the behaviour is by design like this, but basically we have to call the toMediaCollection method to ensure that the database is up to date and that the model_type is updated. I was using it with the temporary uploads functionality (which is enabled by default I think) and didn't call the method toMediaCollection because I only have a default one, but noticed that I couldn't retrieve any media-files.

After a bit of reading source code and debugging I noticed that we have to call this, so that the PendingMediaItem is converted to the associated model.

Hope my explanation makes sense.

so my code was basically:

$model
    ->addFromMediaLibraryRequest($request->attachments)
    ->usingName(fn(MediaLibraryRequestItem $item) => strtolower($item->name));

and had to change it to

$model
    ->addFromMediaLibraryRequest($request->attachments)
    ->usingName(fn(MediaLibraryRequestItem $item) => strtolower($item->name))
    ->toMediaCollection();

I am using medialibrary v10 and pro v2 with the blade directives.

Hope this helps

Not sure if I missed it somewhere else, but I guess the behaviour is by design like this, but basically we have to call the `toMediaCollection` method to ensure that the database is up to date and that the `model_type` is updated. I was using it with the temporary uploads functionality (which is enabled by default I think) and didn't call the method `toMediaCollection`  because I only have a default one, but noticed that I couldn't retrieve any media-files.

After a bit of reading source code and debugging I noticed that we have to call this, so that the `PendingMediaItem` is converted to the associated model.

Hope my explanation makes sense.

so my code was basically:
```php
$model
            ->addFromMediaLibraryRequest($request->attachments)
            ->usingName(fn(MediaLibraryRequestItem $item) => strtolower($item->name));
```

and had to change it to
```php
$model
            ->addFromMediaLibraryRequest($request->attachments)
            ->usingName(fn(MediaLibraryRequestItem $item) => strtolower($item->name))
            ->toMediaCollection();
```

I am using medialibrary v10 and pro v2 with the blade directives.

Hope this helps
@freekmurze freekmurze merged commit 390b50e into spatie:main Mar 22, 2022
@freekmurze
Copy link
Member

Thanks!

@SahinU88 SahinU88 deleted the patch-1 branch March 22, 2022 08:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants