Giter Club home page Giter Club logo

Comments (5)

danharrin avatar danharrin commented on September 26, 2024 1

In #11863 you can add allCollections() to show media from all collections

from filament.

danharrin avatar danharrin commented on September 26, 2024

This was an unfortunate breaking change but it's for the best. It only happens when you have a typed $record arg. We made the change so we aren't eager loading media from collections we do not use.

You need to return null if the $record is null, so all images get eager loaded in.

Alternatively, $record->media()->first()?->collection_name looks like you don't even need collection() at all, it is just getting whatever collection is defined. It's also an N+1 query. Maybe remove it?

from filament.

monteduro avatar monteduro commented on September 26, 2024

This is exactly what i need. Show in a table all the records with his own media that can be “images” or “documents” (i’ve a fallback image for supported extension) or whatever. Mine is a media library where a model is related to a spatie model. This way i can reference that model anywhere in my project and a single media can be used on multiple other entities.

from filament.

danharrin avatar danharrin commented on September 26, 2024

Yeah, so you should be able to remove the collection() to load all media?

from filament.

monteduro avatar monteduro commented on September 26, 2024

If I remove the collection() method, the block of code in applyEagerLoading will default to filtering by 'default,' and then nothing will be returned as media because all of my media elements are either 'images' or 'documents.'

I think that the modifyMediaQuery should only be executed if a collection() is provided; otherwise, it will always default to 'default' and will not display anything as an image.

I understand that we are discussing a SpatieMediaLibraryImageColumn, so it should always be an 'image' or something similar, but I still display icons for other types of documents.

A possible solution could be to use $this->collection instead of $this->getCollection(). This is because the method will return "default" if nothing is passed to the ->collection() method, whereas $this->collection will be empty if nothing is passed, and then the Builder will not add any filter.

/** @phpstan-ignore-next-line */
$modifyMediaQuery = fn (Builder | Relation $query) => $query
    ->ordered()
    ->when(
        $this->collection,
        fn (Builder | Relation $query, string $collection) => $query->where(
            'collection_name',
            $collection,
        ),
    );

Screenshot 2024-03-11 alle 13 04 09

from filament.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.