Skip to content
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

Enum column name "_backoffice" works fine, but "BACKOFFICE" shows empty value #34

Closed
martinschenk opened this issue Apr 22, 2021 · 7 comments

Comments

@martinschenk
Copy link

I cant change the database column name because its used by others.
When the column name of the enum field is "_backoffice" the nove enum filed works perfect.
But when the column name is "BACKOFFICE" the nova enum column and filed shows empty.

by default 2021-04-22 at 15 56 28

by default 2021-04-22 at 15 57 50

by default 2021-04-22 at 15 58 26

by default 2021-04-22 at 15 58 42

by default 2021-04-22 at 15 58 54

@mdpoulter
Copy link
Member

Hi @martinschenk. Could you possibly provide some more details as it's difficult to work out what's going on?

@martinschenk
Copy link
Author

martinschenk commented Apr 22, 2021 via email

@martinschenk
Copy link
Author

here a more detailed explication:

the mysql database table has an enum column named "BACKOFFICE".
The ENUM definition is: 'S','N', Allow NULL, Default N

Record 1 of the table has set the ENUM field to 'S'

I created the class SiNo:

    final class SiNo extends Enum
    {
        const S = 'S';
        const N = 'N';
    } 

My Model:

    class Perfil extends Model
    {
        use CastsEnums;
    
        protected $casts = [
            'BACKOFFICE' => SiNo::class
        ];

My Nova Model:

 Enum::make('BACKOFFICE')->attach(SiNo::class),

If i call now the nova page,

  • the index (list) view of the BACKOFFICE field shows up empty = "----" like in the first screenshot above.
  • the edit field of the record shows: "choose an option" with the dropdown and the possibilities S and N. (But as you remember, in the database, there is set S.

No i make just some very small changes to get it working:
1.) i change the name of the table from BACKOFFICE to _backoffice
2.) i change in the model

    '_backoffice' => SiNo::class

3.) i change in the nova model

  Enum::make('_backoffice')->attach(SiNo::class),

Now it works all perfect!

In the list view i get the real database values and in the edit view he show also the correct values.

My problem:
As the database is used also by other services, i can not rename the column name from BACKOFFICE to _backoffice.

So how can i get it to work please?

mysql Ver 14.14 Distrib 5.7.32, for osx10.15
PHP 7.4.16 (cli)
Laravel 8

@mdpoulter
Copy link
Member

Thanks for the further details. I will see if I can replicate the problem this weekend.

@martinschenk
Copy link
Author

martinschenk commented Apr 23, 2021 via email

@martinschenk
Copy link
Author

Resolved.

I added in config/datababese.php

PDO::ATTR_CASE => PDO::CASE_LOWER

'mysql' => [
      'options' => extension_loaded('pdo_mysql') ? array_filter([
                 PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
                 PDO::ATTR_CASE => PDO::CASE_LOWER
        ]) : [],
],

then i had to change all field names in the code to lowercase.

Now works, fine. Thanks

@mdpoulter
Copy link
Member

Okay great! Glad to hear it. This sounds like quite an edge case scenario, so I'll close the issue for now unless someone else runs into it.

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

No branches or pull requests

2 participants