Accessors and Mutators in Laravel 5.3

Asked

Viewed 85 times

0

How do I run my own method in Accessors and Mutators of Laravel 5.3 it works with the methods of PHP itself, but if I try to use a method of my own, it gives error.

I’ve tried it like this:

public function getUsuTelefoneAttribute($value) {
    $generalInfo = new GeneralInfo();
    $this->attributes['usu_telefone'] = $generalInfo->masc_tel($value);
}

and tried so:

public function getUsuTelefoneAttribute($value, GeneralInfo $generalInfo) {
    $this->attributes['usu_telefone'] = $generalInfo->masc_tel($value);
}

but both make a mistake

  • The original is like?

  • What do you want to do with that method? What do you want me to return from the phone?

  • is a mask you want in the output of the result of usu_telefone??? is the first form that is correct (seeing so over) and what you call? maybe you’re having this confusion.

  • I have in the database the phone saved like this: 1199999999 and I want it to show like this (65) 999-9999 need to apply this filter there in getattribute for this

No answers

Browser other questions tagged

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