Laravel-Backpack / CRUD

Build custom admin panels. Fast!
https://backpackforlaravel.com
MIT License
3.08k stars 886 forks source link

[Bug] missing custom columns from scope in list view #4777

Closed HeriDCLXVI closed 1 year ago

HeriDCLXVI commented 1 year ago

Bug report

What I did

i added a scope with custom columns to filter data in list view $builder->selectRaw('(custom_query1) as full_count, (custom_query2) as work_unit_count')->havingRaw('full_count = work_unit_count');

What I expected to happen

the data is filtered

What happened

error because my custom columns from scope is missing image

What I've already tried to fix it

added $this->crud->setOperationSetting('totalEntryCount', $this->crud->query->count()); in setupListOperation, but the same error happens again when i try to use filter in the list view

Is it a bug in the latest version of Backpack?

After I run composer update backpack/crud the bug... is it still there? yes, it is a bug caused by v5.4.0

Backpack, Laravel, PHP, DB version

When I run php artisan backpack:version the output is:

PHP VERSION:

PHP 8.1.2 (cli) (built: Jul 21 2022 12:10:37) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.2, Copyright (c) Zend Technologies with Zend OPcache v8.1.2, Copyright (c), by Zend Technologies

LARAVEL VERSION:

v9.40.1@9611fdaf2db5759b8299802d7185bcdbee0340bb

BACKPACK VERSION:

5.4.7@6e1bb116de9f3091530cb9b11edcceb4d252daa8

pxpm commented 1 year ago

Hey @HeriDCLXVI

Can you make sure you are using the $this->crud->addBaseClause('scopeName') ? Or is it a global model scope ?

Cheers

HeriDCLXVI commented 1 year ago

Hi @pxpm,

image this is how i use the scope, i added this in the Model, so i think it is a global model scope

tabacitu commented 1 year ago

@pxpm ? Bump!

pxpm commented 1 year ago

Hey @tabacitu and @HeriDCLXVI I've been working on this for the past days.

I had the branch already created but haven't created the PR yet, so I did it a few moments ago: https://github.com/Laravel-Backpack/CRUD/pull/4788

It would help alot @HeriDCLXVI if you are able to pull the branch and test if it solves your use case too. You can do that by forcing composer to use that branch with: composer require backpack/crud:"dev-always-use-the-selectRaw-expressions as 5.4.99"

Thanks for the report and let me know if you give it a test 🙏

Cheers

HeriDCLXVI commented 1 year ago

Hi @pxpm ,

i have tested using that branch and it is working now

pxpm commented 1 year ago

Thanks for confirming @HeriDCLXVI and for providing the info that made me able to debug it 🙏

I will be closing this in favor of the PR, should be reviewed by some other team member and merged in the next release.

Cheers