SettingsController.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 tabs as laravel view paths
  19. $tabs = [];
  20. if(file_exists(Theme::getViewPaths()[0] . '/admin/settings/tabs/')){
  21. $tabspath = glob(Theme::getViewPaths()[0] . '/admin/settings/tabs/*.blade.php');
  22. }else{
  23. $tabspath = glob(Theme::path($path = 'views', $themeName = 'default').'/admin/settings/tabs/*.blade.php');
  24. }
  25. foreach ($tabspath as $filename) {
  26. $tabs[] = 'admin.settings.tabs.'.basename($filename, '.blade.php');
  27. }
  28. //Generate a html list item for each tab based on tabs file basename, set first tab as active
  29. $tabListItems = [];
  30. foreach ($tabs as $tab) {
  31. $tabName = str_replace('admin.settings.tabs.', '', $tab);
  32. $tabListItems[] = '<li class="nav-item">
  33. <a class="nav-link '.(empty($tabListItems) ? 'active' : '').'" data-toggle="pill" href="#'.$tabName.'">
  34. '.__(ucfirst($tabName)).'
  35. </a></li>';
  36. }
  37. $themes = array_diff(scandir(base_path('themes')), array('..', '.'));
  38. return view('admin.settings.index', [
  39. 'tabs' => $tabs,
  40. 'tabListItems' => $tabListItems,
  41. 'themes' => $themes,
  42. 'active_theme' => Theme::active(),
  43. ]);
  44. }
  45. }