Skip to content

Commit 0106e27

Browse files
committed
update readme
1 parent 199a953 commit 0106e27

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

tests/AppendAutomateTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ public function testAppendAutomate()
2525

2626
$user->save();
2727

28-
$user = User::select(['id', 'firstname', 'status'])->first();
28+
$user = User::select(['id', 'firstname', 'gender'])->first();
2929

3030
$this->assertArrayNotHasKey('fullname', $user->toArray());
3131
$this->assertArrayHasKey('first_letter', $user->toArray());
32-
$this->assertArrayHasKey('status_text', $user->toArray());
33-
$this->assertArrayNotHasKey('gender_text', $user->toArray());
32+
$this->assertArrayNotHasKey('status_text', $user->toArray());
33+
$this->assertArrayHasKey('gender_text', $user->toArray());
34+
$this->assertArrayHasKey('access', $user->toArray());
35+
$this->assertArrayHasKey('access_text', $user->toArray());
3436

3537
Model::unguard();
3638
}

tests/Models/User.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class User extends Model
1111
'firstname|lastname' => 'fullname', // firstname 和 lastname 字段缺一不可,否则不返回 fullname
1212
'gender' => 'gender_text', // gender 是一个 int 字段,0:女,1:男
1313
'status' => 'status_text', // status 是一个 int 字段,0:禁用,1:启用
14+
'gender_text' => 'access', // status 是一个 int 字段,0:禁用,1:启用
15+
'access' => 'access_text', // status 是一个 int 字段,0:禁用,1:启用
1416
];
1517

1618
public function getStatusTextAttribute()
@@ -27,9 +29,20 @@ public function getFirstLetterAttribute()
2729
{
2830
return substr($this->firstname, 0, 1);
2931
}
32+
3033
public function getFullnameAttribute()
3134
{
3235
return $this->firstname . ' ' . $this->lastname;
3336
}
3437

38+
public function getAccessAttribute()
39+
{
40+
return $this->gender_text === 'Female';
41+
}
42+
43+
public function getAccessTextAttribute()
44+
{
45+
return $this->access ? 'can' : 'Can not';
46+
}
47+
3548
}

0 commit comments

Comments
 (0)