private $email in User model => no mails sent #34893
-
Hi everyone, I was playing around with Laravel and IntelliJ complained when accessing Model properties via "magic method", like $user->email. So I had the brilliant idea to declare $email as a private property in the User model. A week later I noticed that Laravel doesn't send emails anymore. After lots of diffs and several "composer create-project" I removed the private property in the model, and emails are sent out again. Please note that I am frontend focussed and not very proficient in either Laravel or php. So, am I an idiot for declaring $email as a private property - and if so, why? :) Should I only declare properties that I add to the user model? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
The attributes of your eloquent models that are saved to the database work a bit differently than the normal class properties. If you just want IntelliJ to stop complain and want a better experience with IntelliJ and Laravel in general, you can install barryvdh/laravel-ide-helper, which scans your models/database and auto-generates files for your IDE to know, which attributes your models have. |
Beta Was this translation helpful? Give feedback.
The attributes of your eloquent models that are saved to the database work a bit differently than the normal class properties.
The "database" attributes like
User::email
are actually stored in the$attributes
property (seeHasAttributes
-trait, which the eloquentModel
class uses). Under the hood you can access$user->email
, even though you did not explicitly declare it through PHPs magic-methods__get
and__set
. These basically delegate the calls from$user->email
to actually return$user->attributes['email']
(simplified).If you just want IntelliJ to stop complain and want a better experience with IntelliJ and Laravel in general, you can install barryvdh/laravel-ide-helper, which scans y…