12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- namespace App\Http\Controllers\API;
- use App\Http\Controllers\Controller;
- use App\Http\Requests\API\Config\AllowSettingConfig;
- use App\Models\Config;
- use Illuminate\Http\Request;
- class ConfigController extends Controller
- {
- public function index(Request $request)
- {
- $groups = $request->get("group", []);
- $data = [];
- if ($groups) {
- $data = Config::query()->whereIn("group", $groups)->get([
- 'group', 'key', 'value'
- ])->groupBy("group");
- }
- return $this->success([
- 'data' => $data
- ]);
- }
- public function setting(Request $request)
- {
- $allowSettingConfig = new AllowSettingConfig();
- foreach ($request->all() as $item) {
- try {
- $allowSettingConfig->check($item['group'], $item['key'], $item['value']);
- } catch (\Exception $exception) {
- return $this->forbidden($exception->getMessage());
- }
- }
- foreach ($request->all() as $item) {
- Config::query()->updateOrCreate([
- 'group' => $item['group'],
- 'key' => $item['key'],
- ], [
- 'value' => $item['value']
- ]);
- }
- return $this->noContent();
- }
- }
|