statamic / docs

Statamic Documentation
https://statamic.dev
Other
110 stars 374 forks source link

Remove whereCollection and whereInCollection from docs #1378

Closed j3ll3yfi5h closed 3 months ago

j3ll3yfi5h commented 3 months ago

Methods are not available anymore and throw errors:

Call to undefined method Statamic\Stache\Query\EntryQueryBuilder::whereCollection()

Call to undefined method Statamic\Stache\Query\EntryQueryBuilder::whereInCollection()

duncanmcclean commented 3 months ago

The whereCollection and whereInCollection methods do still exist on the Entry repository/facade.

However, by the looks of those error messages, you're trying to use them on the query builder (where they don't exist)?

j3ll3yfi5h commented 3 months ago

@duncanmcclean Ah interesting, you're right!

Can you maybe explain to me, what is the difference? Most examples on this page https://statamic.dev/repositories/entry-repository are about using the methods in query builders, right? Or am I completely confused?

duncanmcclean commented 3 months ago

So, the methods here are the methods on the Entry facade (& the repository, which is what the facade hits when you call it):

CleanShot 2024-06-20 at 14 07 37

The query method will give you a "query builder" instance. The query builder is another object which lets you query & order entries. It's what lets you do filtering like ->where('foo', 'bar').

The query builder has a different set of methods to those on the repository.

For example:

Entry::query() // the query method makes a "query builder"
    ->where('collection', 'pages') // adds a "condition" to the query, filtering entries to those where the collection = pages
    ->where('foo', 'bar') // adds another "condition" to the query, filtering entries to those where foo = bar
    ->get() // actually executes the query to get the results. the get method returns a Laravel Collection instance
    ->map() // this map method exists on the Laravel Collection instance (which you can find out more about here: https://laravel.com/docs/master/collections)

Does that help?

j3ll3yfi5h commented 3 months ago

@duncanmcclean Aha, I understand. Thank you very much for your explanations!