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

[9.x] Fixes default attribute value when using enums on model:show #43360

Merged
merged 2 commits into from
Jul 22, 2022
Merged

[9.x] Fixes default attribute value when using enums on model:show #43360

merged 2 commits into from
Jul 22, 2022

Conversation

josecl
Copy link
Contributor

@josecl josecl commented Jul 22, 2022

Problem

Having an UnitEnum or BackedEnum as default attribute value in a Model, like this:

    protected $casts = [
        'status' => InvoiceStatus::class,
    ];

    protected $attributes = [
        'status' => InvoiceStatus::I_LOVE_LARAVEL,
    ];

Triggers an error on model:show command:

ERROR: Object of class App\Enums\InvoiceStatus could not be converted to string

Fix

This PR fixes it displaying the value of enums name attribute:

 status fillable ................................... integer / App\Enums\InvoiceStatus
  ⇂ default: I_LOVE_LARAVEL

@taylorotwell taylorotwell merged commit 0f53f65 into laravel:9.x Jul 22, 2022
@jessarcher
Copy link
Member

Hey @josecl,

Thanks for this! I think the error will still occur with the --json flag, so it might be better to move this change to the getColumnDefault() method to fix it everywhere. I'll work up a PR now.

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

Successfully merging this pull request may close these issues.

3 participants