Skip to content

Index Resources

When indexing a resource, you'll likely want useIndex(). However at times we can't use the composition api. For that, we have index().

WARNING

Some backends do not support all the features on this page

With (Including data)

Also known as expand, include and populate (comes in many names depending on your backend). We can fetch related data and apply filters using with.

Filtering Included Data

Advanced filters are possible via VueModel's query object. The query object is inspired by Strapi, and Orion (Laravel)

Querying nested data has been meticulously typed. Consider using ctrl + space as you write the query to see what filters, fields and relationships you have available:

ts
const response = await index(User, {
  with: {
    posts: {
      title: {
        contains: 'est',
      },
    },
  },
})

Filtering (And/Or Blocks)

We can even filter using an or block! and blocks are also supported.

js
index(User, {
    includes: {
      posts: {
        body: {
          contains: 'est',
        },
        or: [
          {
            created_at: {
              greaterThan: '2023-08-02',
            },
          },
          {
            user_id: {
              equals: '1',
            },
          },
        ],
      },
    },
  })

In the above example:

  • every post must have a body that contains 'est'
  • the post must also be created after '2023-08-02' OR have a user_id of '1'

Order By

Of course, we can order our results.

Nested Order By

And order nested records at any level!

Pagination

Of course, we can also paginate the results.