Skip to content

feat: add relation resolver param to order callback #3232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Seb33300
Copy link
Contributor

@Seb33300 Seb33300 commented May 5, 2025

Same as #3229 but for orderColumn()

In #3216, I added the $column parameter to pass the current column alias to the order callback function, but this is not really helpful when we want to work on other columns as reported by @Arkhas.

So I decided to replace this param by the resolver in the same way as filterColumn()

$datatable = new EloquentDataTable($query);

$datatable
    ->orderColumn('foo.bar', function ($query, $order, $resolver) {
        // $resolver automatically create joins if needed
        $query->orderBy($resolver('foo.bar'), $order);
        // or
        $query->orderBy(DB::raw("{$resolver('foo.amount')} * {$resolver('foo.quantity')}"), $order);
    })
;

Copy link

sonarqubecloud bot commented May 5, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant