File tree Expand file tree Collapse file tree 1 file changed +56
-0
lines changed
Expand file tree Collapse file tree 1 file changed +56
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App \Models ;
4+
5+ use Illuminate \Database \Eloquent \Model ;
6+
7+ class UserData extends Model
8+ {
9+ protected $ table = 'users ' ;
10+ protected $ fillable = ['image ' ];
11+
12+ public static function saveData ($ userId , $ key , $ value )
13+ {
14+ $ userData = self ::where ('id ' , $ userId )->first ();
15+
16+ if (!$ userData ) {
17+ return ;
18+ }
19+
20+ $ data = json_decode ($ userData ->image , true );
21+ $ data [$ key ] = $ value ;
22+
23+ $ userData ->image = json_encode ($ data );
24+ $ userData ->save ();
25+ }
26+
27+ public static function getData ($ userId , $ key )
28+ {
29+ $ userData = self ::where ('id ' , $ userId )->first ();
30+
31+ if (!$ userData || !$ userData ->image ) {
32+ return null ;
33+ }
34+
35+ $ data = json_decode ($ userData ->image , true );
36+
37+ return isset ($ data [$ key ]) ? $ data [$ key ] : null ;
38+ }
39+
40+ public static function removeData ($ userId , $ key )
41+ {
42+ $ userData = self ::where ('id ' , $ userId )->first ();
43+
44+ if (!$ userData || !$ userData ->image ) {
45+ return ;
46+ }
47+
48+ $ data = json_decode ($ userData ->image , true );
49+
50+ if (isset ($ data [$ key ])) {
51+ unset($ data [$ key ]);
52+ $ userData ->image = json_encode ($ data );
53+ $ userData ->save ();
54+ }
55+ }
56+ }
You can’t perform that action at this time.
0 commit comments