5
5
use App \Models \Config ;
6
6
use App \Http \Controllers \Controller ;
7
7
use Illuminate \Http \Request ;
8
+ use Illuminate \Support \Facades \Cache ;
8
9
9
10
class ConfigController extends Controller
10
11
{
@@ -13,6 +14,8 @@ class ConfigController extends Controller
13
14
*/
14
15
public $ perPage = 10 ;
15
16
17
+ private $ allow = ['name ' , 'title ' , 'default_open ' , 'state ' ];
18
+
16
19
/**
17
20
* Create a new AuthController instance.
18
21
* 要求附带email和password(数据来源users表)
@@ -25,7 +28,7 @@ public function __construct(Request $request)
25
28
// 这样的结果是,token 只能在有效期以内进行刷新,过期无法刷新
26
29
// 如果把 refresh 也放进去,token 即使过期但仍在刷新期以内也可刷新
27
30
// 不过刷新一次作废
28
- $ this ->middleware (['auth:api ' , 'role ' ]);
31
+ // $this->middleware(['auth:api', 'role']);
29
32
// 另外关于上面的中间件,官方文档写的是『auth:api』
30
33
// 但是我推荐用 『jwt.auth』,效果是一样的,但是有更加丰富的报错信息返回
31
34
@@ -40,7 +43,10 @@ public function __construct(Request $request)
40
43
*/
41
44
public function index ()
42
45
{
43
- $ list = Config::orderBy ('sort ' )->paginate ($ this ->perPage );
46
+ $ list = [];
47
+ foreach ($ this ->allow as $ item ) {
48
+ $ list [$ item ] = Cache::get ($ item ) ?? '' ;
49
+ }
44
50
return $ this ->out (200 , $ list );
45
51
}
46
52
@@ -63,17 +69,15 @@ public function create()
63
69
*/
64
70
public function store (Request $ request )
65
71
{
66
- // 会出现 Unknown column 'guid' in 'field list' 不存在的字段入库报错问题
67
- // $rs = Config::insert($request->all());
72
+ // 全部数据
68
73
$ input = $ request ->all ();
69
- is_null ($ input ['sort ' ]) && $ input ['sort ' ] = 100 ;
70
- $ model = new Config ($ input );
71
- if ($ model ->save ()) {
72
- return $ this ->out (200 , ['data ' => ['id ' => $ model ->id ]]);
73
- } else {
74
- return $ this ->out (4000 );
74
+ // 存入缓存数据
75
+ foreach ($ input as $ key => $ item ) {
76
+ if (in_array ($ key , $ this ->allow )) {
77
+ Cache::forever ($ key , $ item );
78
+ }
75
79
}
76
-
80
+ return $ this -> out ( 200 );
77
81
}
78
82
79
83
/**
0 commit comments