Git Product home page Git Product logo

Comments (4)

neilgilmour avatar neilgilmour commented on July 17, 2024 2

There's some info about this on the Query Builder docs: https://spatie.be/docs/laravel-query-builder/v3/features/including-relationships#selecting-included-fields

from inertiajs-tables-laravel-query-builder.

pascalbaljet avatar pascalbaljet commented on July 17, 2024 1

The QueryBuilder also accepts an Eloquent Builder, so you could do something like this:

QueryBuilder::for(SomeModel::with('users'))

from inertiajs-tables-laravel-query-builder.

jbunning avatar jbunning commented on July 17, 2024 1

@zamblas you can aggregate the relations columns in the query builder:

QueryBuilder::for(Model::class)
->withAggregate('relation', 'column')

Then use like this:

$table->column('relation_column', 'Displayed name', sortable: true, searchable: true);

from inertiajs-tables-laravel-query-builder.

zamblas avatar zamblas commented on July 17, 2024

Is there any example available?

On a users table, I'm trying to add a column with the user role.
Got it to show using QueryBuilder::for(User::with('roles')) on the controller and on the .vue

<template #cell(roles)="{ item: user }">
    {{ user.roles.map(role => role.name).join(', ') }}
</template>

But when sorting that column it gives an error Unknown column 'roles' in 'order clause'.

How can I sort by relationship? I've tried adding 'roles', 'roles.name' to allowedSorts but with no success

from inertiajs-tables-laravel-query-builder.

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.