SettingsController.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Http\Controllers\Admin;
  3. use App\Http\Controllers\Controller;
  4. use Illuminate\Contracts\Foundation\Application;
  5. use Illuminate\Contracts\View\Factory;
  6. use Illuminate\Contracts\View\View;
  7. use Illuminate\Http\Response;
  8. use Qirolab\Theme\Theme;
  9. class SettingsController extends Controller
  10. {
  11. /**
  12. * Display a listing of the resource.
  13. *
  14. * @return Application|Factory|View|Response
  15. */
  16. public function index()
  17. {
  18. // get all other settings in app/Settings directory
  19. // group items by file name like $categories
  20. $settings = collect();
  21. foreach (scandir(app_path('Settings')) as $file) {
  22. if (in_array($file, ['.', '..'])) {
  23. continue;
  24. }
  25. $className = 'App\\Settings\\' . str_replace('.php', '', $file);
  26. $options = (new $className())->toArray();
  27. if (method_exists($className, 'getOptionInputData')) {
  28. $optionInputData = $className::getOptionInputData();
  29. } else {
  30. $optionInputData = [];
  31. }
  32. $optionsData = [];
  33. foreach ($options as $key => $value) {
  34. $optionsData[$key] = [
  35. 'value' => $value,
  36. 'label' => $optionInputData[$key]['label'] ?? ucwords(str_replace('_', ' ', $key)),
  37. 'type' => $optionInputData[$key]['type'] ?? 'string',
  38. 'description' => $optionInputData[$key]['description'] ?? '',
  39. 'options' => $optionInputData[$key]['options'] ?? [],
  40. ];
  41. }
  42. $settings[str_replace('Settings.php', '', $file)] = $optionsData;
  43. }
  44. $settings->sort();
  45. $themes = array_diff(scandir(base_path('themes')), array('..', '.'));
  46. return view('admin.settings.index', [
  47. 'settings' => $settings->all(),
  48. 'themes' => $themes,
  49. 'active_theme' => Theme::active(),
  50. ]);
  51. }
  52. }