SettingsController.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace App\Http\Controllers\Admin\SettingsControllers;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\InvoiceSettings;
  5. use Illuminate\Contracts\Foundation\Application;
  6. use Illuminate\Contracts\View\Factory;
  7. use Illuminate\Contracts\View\View;
  8. use Illuminate\Http\Request;
  9. use Illuminate\Http\Response;
  10. class SettingsController extends Controller
  11. {
  12. /**
  13. * Display a listing of the resource.
  14. *
  15. * @return Application|Factory|View|Response
  16. */
  17. public function index()
  18. {
  19. //Get all tabs as laravel view paths
  20. $tabs = [];
  21. foreach (glob(resource_path('views/admin/settings/tabs/*.blade.php')) as $filename) {
  22. $tabs[] = 'admin.settings.tabs.' . basename($filename, '.blade.php');
  23. }
  24. //Generate a html list item for each tab based on tabs file basename, set first tab as active
  25. $tabListItems = [];
  26. foreach ($tabs as $tab) {
  27. $tabName = str_replace('admin.settings.tabs.', '', $tab);
  28. $tabListItems[] = '<li class="nav-item">
  29. <a class="nav-link ' . (empty($tabListItems) ? 'active' : '') . '" data-toggle="pill" href="#' . $tabName . '">
  30. ' . __(ucfirst($tabName)) . '
  31. </a></li>';
  32. }
  33. return view('admin.settings.index', [
  34. 'tabs' => $tabs,
  35. 'tabListItems' => $tabListItems,
  36. ]);;
  37. }
  38. public function updateIcons(Request $request)
  39. {
  40. $request->validate([
  41. 'icon' => 'nullable|max:10000|mimes:jpg,png,jpeg',
  42. 'favicon' => 'nullable|max:10000|mimes:ico',
  43. ]);
  44. if ($request->hasFile('icon')) {
  45. $request->file('icon')->storeAs('public', 'icon.png');
  46. }
  47. if ($request->hasFile('favicon')) {
  48. $request->file('favicon')->storeAs('public', 'favicon.ico');
  49. }
  50. return redirect()->route('admin.settings.index')->with('success', __('Icons updated!'));
  51. }
  52. public function updateInvoiceSettings(Request $request)
  53. {
  54. $request->validate([
  55. 'logo' => 'nullable|max:10000|mimes:jpg,png,jpeg',
  56. ]);
  57. InvoiceSettings::updateOrCreate([
  58. 'id' => "1"
  59. ], [
  60. 'company_name' => $request->get('company-name'),
  61. 'company_adress' => $request->get('company-address'),
  62. 'company_phone' => $request->get('company-phone'),
  63. 'company_mail' => $request->get('company-mail'),
  64. 'company_vat' => $request->get('company-vat'),
  65. 'company_web' => $request->get('company-web'),
  66. 'invoice_prefix' => $request->get('invoice-prefix'),
  67. ]);
  68. if ($request->hasFile('logo')) {
  69. $request->file('logo')->storeAs('public', 'logo.png');
  70. }
  71. return redirect()->route('admin.settings.index')->with('success', 'Invoice settings updated!');
  72. }
  73. }