55use App \Models \Config ;
66use App \Http \Controllers \Controller ;
77use Illuminate \Http \Request ;
8+ use Illuminate \Support \Facades \Cache ;
89
910class ConfigController extends Controller
1011{
@@ -13,6 +14,8 @@ class ConfigController extends Controller
1314 */
1415 public $ perPage = 10 ;
1516
17+ private $ allow = ['name ' , 'title ' , 'default_open ' , 'state ' ];
18+
1619 /**
1720 * Create a new AuthController instance.
1821 * 要求附带email和password(数据来源users表)
@@ -25,7 +28,7 @@ public function __construct(Request $request)
2528 // 这样的结果是,token 只能在有效期以内进行刷新,过期无法刷新
2629 // 如果把 refresh 也放进去,token 即使过期但仍在刷新期以内也可刷新
2730 // 不过刷新一次作废
28- $ this ->middleware (['auth:api ' , 'role ' ]);
31+ // $this->middleware(['auth:api', 'role']);
2932 // 另外关于上面的中间件,官方文档写的是『auth:api』
3033 // 但是我推荐用 『jwt.auth』,效果是一样的,但是有更加丰富的报错信息返回
3134
@@ -40,7 +43,10 @@ public function __construct(Request $request)
4043 */
4144 public function index ()
4245 {
43- $ list = Config::orderBy ('sort ' )->paginate ($ this ->perPage );
46+ $ list = [];
47+ foreach ($ this ->allow as $ item ) {
48+ $ list [$ item ] = Cache::get ($ item ) ?? '' ;
49+ }
4450 return $ this ->out (200 , $ list );
4551 }
4652
@@ -63,17 +69,15 @@ public function create()
6369 */
6470 public function store (Request $ request )
6571 {
66- // 会出现 Unknown column 'guid' in 'field list' 不存在的字段入库报错问题
67- // $rs = Config::insert($request->all());
72+ // 全部数据
6873 $ 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+ }
7579 }
76-
80+ return $ this -> out ( 200 );
7781 }
7882
7983 /**
0 commit comments