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

-2

When I use the accessor with a field eg "full_name", I put it in the model: public function getNomeCompletoAttribute ($ value) works perfectly. When I have a field "address_c", I put it in the model: public function getEnderecoCAttribute ($ value) does not work, the impression I have is that it can not find the field.     

asked by anonymous 02.04.2016 / 16:36

1 answer

0

There is erroneous information in the question:

Access methods of Laravel do not require a parameter.

Example:

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

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

What do you call "does not work"?

The value is returning NULL ?

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

Finally, the functionality works as expected.

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

 $model->getEnderecoCAttribute();

What does this return? Maybe there's the answer to your problem.

    
11.04.2016 / 16:44