Laravel-Backpack / medialibrary-uploaders

MIT License
10 stars 4 forks source link

[Bug] Undefined variable $modelDefinition #5

Closed tabacitu closed 1 year ago

tabacitu commented 1 year ago

Bug report

What I did

    protected function setupCreateOperation()
    {
        CRUD::field('name')->validationRules('required|min:5');
        CRUD::field('email')->validationRules('required|email|unique:users,email');
        CRUD::field('password')->validationRules('required');
        CRUD::field('avatar')->type('image')->withMedia();

        User::creating(function ($entry) {
            $entry->password = \Hash::make($entry->password);
        });
    }

What I expected to happen

Work. Create page load.

What happened

No work. Create page throw ugly Undefined variable $modelDefinition error:

CleanShot 2023-02-24 at 11 39 24

Here's the whole error stack: https://flareapp.io/share/353GGeo5#F58

What I've already tried to fix it

Nothing. I assume the problem is in MediaField::definition() because I see the IF statement there only treats ONE scenario... if the collection is defined. If not... big bubu, and it calls a $mediaDefinition that... doesn't exist.

Later edit: I ended up passing default for the collection for now, to bypass this error, as that's what it seemed to want. But this is still a big bug. It should NOT require the collection parameter, especially since we can assume default 😅

CRUD::field('avatar')->type('image')->withMedia([
            'collection' => 'default',
        ]);
tabacitu commented 1 year ago

For my future self, here are the repositories in composer.json:

    "repositories": {
        "backpack": {
            "type": "composer",
            "url": "https://repo.backpackforlaravel.com/"
        },
        "backpack/media-library-uploads": {
            "type": "vcs",
            "url": "git@github.com:Laravel-Backpack/media-library-uploads.git"
        }
    },
tabacitu commented 1 year ago

Woohooo it works with the fix above:

Edit by Pedro:

removed image due to email leaking

PS: only after removing I remembered that this is private package.

But hey, could go live anytime, and I'd rather not have my email leaked 🤷