Answer the question
In order to leave comments, you need to log in
Why doesn't the getAttribute method write class properties?
Hello everyone again. The article model has some method "getUserIdAttribute()" that reads the ID of the author of this article. Also, there is a public property "author" which is an array. The above method writes the necessary author parameters to this property:
public function getUserIdAttribute($value) {
$this->author['name'] = User::find($value)->username;
$this->author['id'] = $value;
}
User::find($value)->username
, as far as I understand, reads all user fields under the number $value from the database and then takes the value of the "username" field? Should I do something like this to only count the required fields?User::where('id', '=', $value)->first();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question