SettingsController.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. foreach ($options as $key => $value) {
  28. $options[$key] = [
  29. 'value' => $value,
  30. 'label' => ucwords(str_replace('_', ' ', $key))
  31. ];
  32. }
  33. $settings[str_replace('Settings.php', '', $file)] = $options;
  34. }
  35. $settings->sort();
  36. $themes = array_diff(scandir(base_path('themes')), array('..', '.'));
  37. return view('admin.settings.index', [
  38. 'settings' => $settings->all(),
  39. 'themes' => $themes,
  40. 'active_theme' => Theme::active(),
  41. ]);
  42. }
  43. }