N
N
Nikolino2019-10-31 18:08:38
Laravel
Nikolino, 2019-10-31 18:08:38

The getFirstNameAttribute() accessor/mutator doesn't mutate number fields?

Laravel 6.3
The model has a field of the form: $model->photo_1
I want to make an accessor that mutates the value of the field.
public function getPhoto1Attribute($value)
{
return 'test';
}
When I request the $model->photo_1 field, I get the original (unmutated) value, although I expect to see 'test'.
Why?
The doc does not specify how to work with such fields, but according to this method, I have the correct name of the get method:

public function hasGetMutator($key)
    {
        return method_exists($this, 'get'.Str::studly($key).'Attribute');
    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question