Skip to content

Getting dublicated rows when using "hasOne" in model #1840

Closed Answered by oberator
oberator asked this question in Q&A
Discussion options

You must be logged in to vote

How could I have overlooked the fact that the sortabel method also allows a callback. Thank you very much for this hint.

My column now looks like this and works as expected:

Column::make('Compensation')
    ->label(function ($row) {
        return (number_format($row->getCompensation(Carbon::now()->toDateString()), 0, '.', '.') . ' EUR');
    })
    ->sortable(
        fn(Builder $query, string $direction) =>
        $query->orderBy(
            Compensation::select('amount')
                ->whereColumn('compensations.employee_id', 'employees.id')
                ->orderBy('startdate', 'desc')
                ->limit(1),
            $direction
        )
    ),

Replies: 3 comments 8 replies

Comment options

lrljoe
Aug 14, 2024
Collaborator Sponsor

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@lrljoe
Comment options

lrljoe Aug 16, 2024
Collaborator Sponsor

@thomasgalue
Comment options

@lrljoe
Comment options

lrljoe Aug 17, 2024
Collaborator Sponsor

Comment options

lrljoe
Aug 16, 2024
Collaborator Sponsor

You must be logged in to vote
5 replies
@oberator
Comment options

@lrljoe
Comment options

lrljoe Aug 24, 2024
Collaborator Sponsor

@oberator
Comment options

Answer selected by lrljoe
@lrljoe
Comment options

lrljoe Aug 25, 2024
Collaborator Sponsor

@lrljoe
Comment options

lrljoe Aug 31, 2024
Collaborator Sponsor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants