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

[Bug] Method Spatie\MediaLibrary\MediaCollections\Models\Collections\MediaCollection::delete does not exist in a nested model #23

Open
xenorum opened this issue Dec 3, 2023 · 9 comments
Assignees
Labels
bug Something isn't working Priority: MUST

Comments

@xenorum
Copy link

xenorum commented Dec 3, 2023

Bug report

What I did

  • I have a model Post with a related model (HasOne) SubPost with media
  • A CRUD for Post that includes a SubPost
  • Whenever I would create (or update) a model, the error Method Spatie\MediaLibrary\MediaCollections\Models\Collections\MediaCollection::delete does not exist. arises

What I expected to happen

Media gets deleted and uploaded (if needed)

What I've already tried to fix it

I've tried also tried with a 'relationship' field, same error.

Context to replicate the bug - Backpack, Laravel, PHP, DB version

See https://github.com/xenorum/backpack-media-repeatable for an example of the setup

Thanks for your insights, I am stuck on this one.

@karandatwani92
Copy link

karandatwani92 commented Dec 4, 2023

Hey @xenorum

Your example repo is using a repeatable field

So I created a similar field to test and I found upload & delete working for me:

[
    'name'      => 'sub_posts',
    'type'      => 'repeatable',
    'subfields' => [
        [
            'name'    => 'title',
            'wrapper' => [
                'class' => 'col-md-3',
            ],
        ],
        [
            'name'    => 'image',
            'type'    => 'image',
            'withMedia'    => [],
            'wrapper' => [
                'class' => 'col-md-9',
            ],
        ],                    
    ],
]

MODEL

protected $casts = [
'sub_posts'  => 'array',
]

can you run composer update and try again?

If you continue facing this issue, please share the error stack trace.

@karandatwani92
Copy link

Hey @xenorum

Your example repo is using a repeatable field

So I created a similar field to test and I found upload & delete working for me:

[
    'name'      => 'sub_posts',
    'type'      => 'repeatable',
    'subfields' => [
        [
            'name'    => 'title',
            'wrapper' => [
                'class' => 'col-md-3',
            ],
        ],
        [
            'name'    => 'image',
            'type'    => 'image',
            'withMedia'    => [],
            'wrapper' => [
                'class' => 'col-md-9',
            ],
        ],                    
    ],
]

MODEL

protected $casts = [
'sub_posts'  => 'array',
]

For now, the difference I found in your repo & my project is:

Mine was using "spatie/laravel-medialibrary": "^10.7",
Your is "spatie/laravel-medialibrary": "^10.0.0"

can you run composer update and try again?

If you continue facing this issue, please share the error stack trace.

@xenorum
Copy link
Author

xenorum commented Dec 4, 2023

Composer update is not doing the trick. Also, with the changes you suggest, it seems the one-to-one relation is gone (not sure if that is an issue).
Would you care to share the "parent" model & "child" model + the CrudController with me?

FYI: stack trace here: https://flareapp.io/share/OmVwGRwP#stack

Thanks in advance for your effort on checking this.

@xenorum
Copy link
Author

xenorum commented Dec 13, 2023

@tabacitu Sorry for the direct mention, any chance you can shed some light on this 🙏

@karandatwani92
Copy link

Hey @xenorum Sorry this took so long to acknowledge the problem and your example repo was using repeatable instead of has one-relationship field.

I tested this again with HasOne - Relationship Field. It threw the error you mentioned.

I'm assigning my colleague to fix it.


Hey @pxpm I used Cave hasOne Monster Relationship to test it:

  • When I create a Monster from Monter CRUD, it works.✅
  • When I create a Monster from a Cave CRUD using relationship field & subfields❌, ERROR!!

@xenorum
Copy link
Author

xenorum commented Feb 21, 2024

Hi, do you happen to have an update on this?

@pxpm
Copy link
Collaborator

pxpm commented Feb 21, 2024

Hey @xenorum sorry not yet.

There was issues in Uploaders that need to be addressed before fixing stuff in this package.

There are two PR's towards fixing uploaders stuff. Laravel-Backpack/CRUD#5440 for example.

Only when we merge them I can spend time fixing this, I think it won't be wise working on this, when it's possible the problem is in the Uploaders and not on this specific package.

This is on my list as soon as we merge the PR's that aim to fix uploaders.

Sorry it took a little bit longer, I am actively working on the uploaders issue.

Thanks for understanding and your patience.

@BenjaminVerhaegen
Copy link

Hello, any news on this topic? Having the same issue.

@pxpm
Copy link
Collaborator

pxpm commented Jun 4, 2024

Hello, any news on this topic? Having the same issue.

Working on media library uploaders this week.
Expect some news by the end of the week 👍

Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Priority: MUST
Projects
Status: No status
Development

No branches or pull requests

4 participants