При выводе из базы возникают дубли записей

При выводе из базы возникают дубли одной и той же записи введите сюда описание изображения

Хотя в базе под этим id только одна запись. Для вывода использую Laravel Livewire Tables

Код

protected array $selectArray = [ 'summary_of_order_monitorings.id as summaryId', 'products', 'count', 'order_number', 'order_opening_date', 'order_closing_date', 'order_real_closing_date', 'availability_of_a_remfund', 'manager', 'order_status', 'description', 'type', 'closing', ];

protected Interfaces $repository;

/**
 * @return void
 */
public function boot(): void
{
    $this->repository = app(Interfaces::class);
    parent::boot(); // TODO: Change the autogenerated stub
}

/**
 * @return \Illuminate\Database\Eloquent\Builder
 */
public function builder(): Builder
{
    return $this->repository->get();
}

/**
 * @return void
 * @throws \Rappasoft\LaravelLivewireTables\Exceptions\DataTableConfigurationException
 */
public function configure(): void
{
    $this->setFilterLayout('slide-down');
    parent::configure(); // TODO: Change the autogenerated stub
    $this->setTdAttributes(function(Column $column) {
        if($column->isField('type') or $column->isField('order_opening_date') or $column->isField('order_closing_date') or $column->isField('order_real_closing_date'
            ) or $column->isField('manager')) {
            return [
                'class' => 'word-break-normal',
            ];
        }
        if($column->isField('products') or $column->isField('order_status') or $column->isField('availability_of_a_remfund') or $column->isField('description')) {
            return [
                'class' => 'w-20 word-break-normal',
            ];
        }
        if($column->isField('closing')) {
            return [
                'class' => 'text-wrap',
            ];
        }
        
        return [];
    });
    $this->setTrAttributes(function($row) {
        if($row->order_closing_date) {
            $closingDate = Carbon::createFromFormat('Y-m-d', $row->order_closing_date);
        } else {
            $closingDate = null;
        }
        if($closingDate) {
            if(($closingDate < now()) and ($row->closing === 0)) {
                return [
                    'class' => 'alert alert-danger',
                ];
            }
            if((($closingDate->toDateString() == now()->addDays(2)->toDateString())
                    or ($closingDate->toDateString() == now()->addDays(1)->toDateString())) and ($row->closing === 0)) {
                return [
                    'class' => 'alert alert-warning',
                ];
            }
        }
        return [];
    });
}

/**
 * @return array
 * @throws \Psr\Container\ContainerExceptionInterface
 * @throws \Psr\Container\NotFoundExceptionInterface
 */
public function filters(): array
{
    $manager = [];
    $repo    = $this->repository->get()->get();
    foreach($repo as $value) {
        $manager[$value['manager']] = trim($value['manager']);
    }
    $manager = ['' => __('app.all')] + array_unique($manager);
    return [
        DateFilter::make(__('app.order_real_closing_date_1'))->filter(function(Builder $builder, string $value) {
            $builder->where('order_real_closing_date', '>=', $value)
                ->where('closing', '=', 0);
        }),
        DateFilter::make(__('app.order_real_closing_date_2'))->filter(function(Builder $builder, string $value) {
            $builder->where('order_real_closing_date', '<=', $value)
                ->where('closing', '=', 0);
        }),
        DateFilter::make(__('app.order_opening_date'))
            ->filter(function(Builder $builder, string $value) {
                $builder->where('order_opening_date', '=', $value);
            }),
        DateFilter::make(__('app.date_of_shipment_under_the_contract_1'))->filter(function(Builder $builder, string $value) {
            $builder->where('order_closing_date', '>=', $value)
                ->where('closing', '=', 0);
        }),
        DateFilter::make(__('app.date_of_shipment_under_the_contract_2'))->filter(function(Builder $builder, string $value) {
            $builder->where('order_closing_date', '<=', $value)
                ->where('closing', '=', 0);
        }),
        SelectFilter::make(__('app.ready'))
            ->options([
                ''  => __('app.all'),
                '1' => __('app.ready'),
                '0' => __('app.no_ready'),
            ])->filter(function(Builder $builder, string $value) {
                $builder->where('closing', '=', $value);
            }),
        SelectFilter::make(__('app.type'))
            ->options([
                ''  => __('app.all'),
                '1' => __('app.winches'),
                '2' => __('app.gearbox'),
                '3' => __('app.tali'),
                '4' => __('app.cranes'),
                '5' => __('app.productions'),
                '6' => __('app.couplings'),
                '7' => __('app.brakes'),
                '8' => __('app.repair'),
                '9' => __('app.engineer_kd'),
            ])->filter(function(Builder $builder, string $value) {
                $builder->where('summary_of_order_monitorings.type', '=', $value);
            }),
        SelectFilter::make(__('app.manager'))
            ->options($manager)
            ->filter(function(Builder $builder, string $value) {
                $builder->where('summary_of_order_monitorings.manager', '=', $value);
            }),
    ];
}

/**
 * @return array
 */
public function columns(): array
{
    return [
        Column::make(__('app.#'), "id")->sortable(),
        Column::make(__('app.nomenclature'), 'products')->sortable()->searchable(),
        Column::make(__('app.count'), 'count')->sortable(),
        Column::make(__('app.order_number'), 'order_number')->sortable()->searchable(),
        Column::make(__('app.order_opening_date'), 'order_opening_date')->sortable()->format(function($value, $row) {
            echo $this->formatDate($row->order_opening_date);
        })->searchable(),
        Column::make(__('app.date_of_shipment_under_the_contract'), 'order_closing_date')->sortable()->format(function($value, $row) {
            echo $this->formatDate($row->order_closing_date);
        })->searchable(),
        Column::make(__('app.date_of_planned_production'), 'order_real_closing_date')->sortable()->format(function($value, $row) {
            echo $this->formatDate($row->order_real_closing_date);
        })->searchable(),
        Column::make(__('app.availability_of_materials'), 'availability_of_a_remfund')->sortable()->searchable(),
        Column::make(__('app.manager'), 'manager')->sortable()->searchable(),
        Column::make(__('app.order_status'), 'order_status'),
        Column::make(__('app.special_note'), 'description')->searchable(),
        Column::make(__('app.type'), 'type')->sortable()->format(
            fn($value, $row, Column $column) => $this->type($row->type)
        )->searchable(),
        BooleanColumn::make(__('app.done_kd_1'), "getKdEngineer.done"),
        BooleanColumn::make(__('app.ready'), 'closing'),
        Column::make(__('app.cost_of_work'), 'cost_of_work')->secondaryHeader(function($rows) {
            return __('app.subtotal') . ': ' . $rows->sum('cost_of_work');
        }),
        $this->disableEnable(Column::make(__('app.closure'))),
        Column::make(__('app.actions'))->label(function($row) {
            echo $this->editButtons($row, 'summary.summary-edit');
        })->html(),
    ];
}

/**
 * @param $row
 *
 * @return \Illuminate\Http\RedirectResponse
 */
public function closing($row): RedirectResponse
{
    if($row['closing']) {
        $result = [
            'closing' => 0,
        ];
    } else {
        $result = [
            'closing' => 1,
        ];
    }
    
    $update = $this->repository->update($row['id'], $result);
    
    return $this->isError($update);
}

/**
 * @param  int  $id
 *
 * @return \Illuminate\Http\RedirectResponse
 */
public function destroy(int $id): RedirectResponse
{
    $delete = $this->repository->destroy($id);
    
    return $this->isError($delete, 'global.err_del');
}

Ответы (1 шт):

Автор решения: Alukard Nosferatu

Нашел решение в запросе добавил ->distinct()

→ Ссылка