Laravel accessors does not work with field separated by _ with a letter

Asked

Viewed 27 times

-2

When I use the accessor with an ex.: "full name" field, I put it in the model: public Function getNomeCompletoAttribute($value) works perfectly. When I have an "address_c" field, I put it in the model: public Function getEnderecoCAttribute($value) does not work, the impression I have is that it does not find the field.

  • I took the test here and everything worked normally.

1 answer

0


There is a misinformation in the question:

The access methods of Laravel do not require parameter.

Example:

public function getEnderecoCAttribute()
{
       return 'Endereço C';
}

And I also did the tests on Laravel 4 and Laravel 5: both worked correctly.

What you call "not working"?

The value is returning NULL?

This may be because you are returning something that is Null, or because the model does not exist (I accidentally already added a method in a model, thinking it was another).

Anyway, the functionality works as expected.

The test that can be done is you call the method directly

 $model->getEnderecoCAttribute();

What does it return? Perhaps there is the answer to your problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.