国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

php - Problems encountered when using the reader (getAttribute) in laravel
PHP中文網(wǎng)
PHP中文網(wǎng) 2017-05-16 12:58:48
0
1
781

The scene is:

When displaying the tel field in a Users table in the foreground, the last 4 digits of the phone number are replaced with *.

The method I use is:

class User extends Model
{
    public function getTelAttribute () {
        return substr($this->attributes['tel'], 0, 7) . '****';
    }
}

If you write it like this, it will generally be fine.

However, when the user modifies personal information through the form, the phone number displayed in the input is

Example: 1391234**

What I want to solve is:

In the case of using the reader (getAttribute), how to
temporarily cancel the action to the reader (getAttribute) under certain conditions, so as to display the complete phone number?

PHP中文網(wǎng)
PHP中文網(wǎng)

認(rèn)證高級(jí)PHP講師

reply all(1)
習(xí)慣沉默

1. Make two

ExportArray時(shí)隱藏一個(gè),這樣做有弊病,導(dǎo)出的JSON接口中,telare all**

protected $hidden = [
    'tel_original'
];

function getTelAttribute() {
    return substr($this->attributes['tel'], 0, 7) . '****');
}

function getTelOriginalAttribute() {
    return $this->attributes['tel'];
}

2. Runtime replacement

No changetel,但是在模板中顯示時(shí),用函數(shù)替換一下
這樣對(duì)導(dǎo)出JSONhas no effect, it just needs to be replaced with a function every time it is displayed

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template