Laravel-Backpack / CRUD

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

[Bug] CRUD Fluent API Does not Support enumFunction #5514

Closed altayevrim closed 2 months ago

altayevrim commented 2 months ago

Bug report

What I did

I tried to use CRUD Fluent API on columns to add a enum column (PHP Enum).

CRUD::column('type')->type('enum')->enumClass(\App\Models\Line::class, 'type')->enumFunction('readableText')->label('Tip');

enumClass and all others work well but enumFunction seems not working

What I expected to happen

The same result when I add the column with this;

$this->crud->column([
            'type' => 'enum',
            'name' => 'type',
            'label' => 'Tip',
            'enum_class' => \App\Enums\LineTypeEnum::class,
            'enum_function' => 'readableText'
        ]);

What happened

Instead of invoking the readableText method of the \App\Enums\LineTypeEnum::class the raw value of from the database been displayed.

What I've already tried to fix it

I think enumFunction should be added to the Fluent API.

Is it a bug in the latest version of Backpack?

I couldn't test it because backpackforlaravel.com seems down at the moment I send this.

Loading composer repositories with package information
https://repo.backpackforlaravel.com could not be fully loaded (curl error 35 while downloading https://repo.backpackforlaravel.com/packages.json: Recv failure: Connection reset by peer), package information was loaded from the local cache and may be out of date

Backpack, Laravel, PHP, DB version

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


php artisan backpack:version
### PHP VERSION:
8.3.6

### PHP EXTENSIONS:
Core, date, libxml, openssl, pcre, sqlite3, zlib, bcmath, bz2, calendar, ctype, curl, dba, dom, hash, FFI, fileinfo, filter, ftp, gd, gmp, json, iconv, SPL, session, intl, standard, ldap, mbstring, mysqlnd, mysqli, pcntl, exif, imap, PDO, pdo_mysql, pdo_pgsql, pdo_sqlite, pgsql, Phar, posix, random, readline, redis, Reflection, imagick, shmop, SimpleXML, soap, sockets, sodium, sysvmsg, sysvsem, sysvshm, tokenizer, xml, xmlreader, xmlwriter, xsl, zip, Zend OPcache

### LARAVEL VERSION:
11.5.0.0

### BACKPACK PACKAGE VERSIONS:
backpack/activity-log: 2.0.4
backpack/basset: 1.3.3
backpack/crud: 6.7.11
backpack/generators: v4.0.5
backpack/logmanager: v5.0.1
backpack/pro: 2.1.13
backpack/revise-operation: 2.0.0
backpack/settings: 3.1.1
backpack/theme-tabler: 1.2.10
``
welcome[bot] commented 2 months ago

Hello there! Thanks for opening your first issue on this repo!

Just a heads-up: Here at Backpack we use Github Issues only for tracking bugs. Talk about new features is also acceptable. This helps a lot in keeping our focus on improving Backpack. If you issue is not a bug/feature, please help us out by closing the issue yourself and posting in the appropriate medium (see below). If you're not sure where it fits, it's ok, a community member will probably reply to help you with that.

Backpack communication channels:

Please keep in mind Backpack offers no official / paid support. Whatever help you receive here, on Gitter, Slack or Stackoverflow is thanks to our awesome awesome community members, who give up some of their time to help their peers. If you want to join our community, just start pitching in. We take pride in being a welcoming bunch.

Thank you!

-- Justin Case The Backpack Robot

karandatwani92 commented 2 months ago

Hey @altayevrim

I doubt enumClass() is working; it must be picking DB values. Can you retry with ->enum_class(\App\Enums\LineTypeEnum::class) & ->enum_function('readableText')?

karandatwani92 commented 2 months ago

Closing it due to no activity! Feel free to reopen it if you continue to face the issue.