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

Illuminate\Database\Eloquent\MissingAttributeException The attribute [phone] either does not exist or was not retrieved for model #1728

Closed
SlyDave opened this issue Dec 10, 2024 · 2 comments

Comments

@SlyDave
Copy link

SlyDave commented Dec 10, 2024

Cashier Stripe Version

15.2

Laravel Version

11.23

PHP Version

8.2

Database Driver & Version

No response

Description

When using Model::preventAccessingMissingAttributes(); and your Billable model doesn't contain name and/or email and/or phone

and you use the syncStripeCustomerDetails method

You get an exception

Illuminate\Database\Eloquent\MissingAttributeException
The attribute [phone] either does not exist or was not retrieved for model [App\Models\Vessel].

This is because Concerns/ManagesCustomer::syncStripeCustomerDetails() calls $this->stripeName(), $this->stripeEmail() and $this->stripePhone() these in turn are simple $this->name ?? null etc. the act of calling $this->name when name doesn't exist as an attribute on the model triggers the Exception.

I believe changing $this->name to $this->hasAttribute('name') ? $this->name : null; fixes the problem.

The work around is to override these methods and use the hasAttribute check, or simply return null if you do not implement those columns.

Steps To Reproduce

  • Enabled Model::preventAccessingMissingAttributes(); in your project
  • call $this->syncStripeCustomerDetails() on a Billable model
Copy link

Thank you for reporting this issue!

As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.

If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.

Thank you!

@driesvints
Copy link
Member

We'd appreciate a PR with these adjustments. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants