File tree Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -25,12 +25,14 @@ public function testAppendAutomate()
25
25
26
26
$ user ->save ();
27
27
28
- $ user = User::select (['id ' , 'firstname ' , 'status ' ])->first ();
28
+ $ user = User::select (['id ' , 'firstname ' , 'gender ' ])->first ();
29
29
30
30
$ this ->assertArrayNotHasKey ('fullname ' , $ user ->toArray ());
31
31
$ 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 ());
34
36
35
37
Model::unguard ();
36
38
}
Original file line number Diff line number Diff line change @@ -11,6 +11,8 @@ class User extends Model
11
11
'firstname|lastname ' => 'fullname ' , // firstname 和 lastname 字段缺一不可,否则不返回 fullname
12
12
'gender ' => 'gender_text ' , // gender 是一个 int 字段,0:女,1:男
13
13
'status ' => 'status_text ' , // status 是一个 int 字段,0:禁用,1:启用
14
+ 'gender_text ' => 'access ' , // status 是一个 int 字段,0:禁用,1:启用
15
+ 'access ' => 'access_text ' , // status 是一个 int 字段,0:禁用,1:启用
14
16
];
15
17
16
18
public function getStatusTextAttribute ()
@@ -27,9 +29,20 @@ public function getFirstLetterAttribute()
27
29
{
28
30
return substr ($ this ->firstname , 0 , 1 );
29
31
}
32
+
30
33
public function getFullnameAttribute ()
31
34
{
32
35
return $ this ->firstname . ' ' . $ this ->lastname ;
33
36
}
34
37
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
+
35
48
}
You can’t perform that action at this time.
0 commit comments