-
Notifications
You must be signed in to change notification settings - Fork 170
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
Provide a simple way to test that a field exists in a model #323
Conversation
When creating a behavior class where most models might have for example, a user_id field, it is very helpful to find out if the current $model you are working with has that field so you can fill it or process it in some cases. For example: CompanyBehavior.php protected function createModel() { $this->model = new $this->modelClass; // set company of new model $this->model->company_id = $this->user()->company_id; if ($this->hasAttribute('user_id')) { $this->model->user_id = $this->user()->id; } return $this->model; } This is a resubmital of: octobercms#321
…hod variable names. Good catch Luke. Sorry I did not catch it first.
It seems that this has been denied for issues by the laravel repo several times You should also use |
@firemankurt if you could make the changes suggested by @tschallacka that would be appreciated. I don't mind being better than Laravel by adding this into October :) |
Use "attributesToArray()" instead of just "attributes". Made PSR-4 compliant
@firemankurt could you add this to the documentation in the Models section? |
@firemankurt are you still interested in this? |
Yes
…On Tue, May 26, 2020, 1:02 PM Luke Towers ***@***.***> wrote:
@firemankurt <https://github.com/firemankurt> are you still interested in
this?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#323 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACJDJPJXD2XULUO3OVKT3MTRTQN3HANCNFSM4FB2XCVQ>
.
|
@firemankurt could you add this to the documentation in the Models section? |
This pull request will be closed and archived in 3 days, as there has been no activity in the last 60 days. |
Hey Luke, |
@firemankurt we're still waiting on your documentation update for the Models docs. Did you happen to have a look at that? |
This pull request will be closed and archived in 3 days, as there has been no activity in the last 60 days. |
When creating a behavior class where most models might have for example, a user_id field, it is very helpful to find out if the current $model you are working with has that field so you can fill it or process it in some cases.
For example:
CompanyBehavior.php
This is a resubmital of: #321