ctrlpanel/app/Http/Controllers/Admin/SettingsControllers/SettingsController.php

89 lines
2.8 KiB
PHP
Raw Normal View History

2021-06-05 09:26:32 +00:00
<?php
namespace App\Http\Controllers\Admin\SettingsControllers;
2021-06-05 09:26:32 +00:00
use App\Http\Controllers\Controller;
2021-12-07 12:16:44 +00:00
use App\Models\InvoiceSettings;
2021-06-05 09:26:32 +00:00
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\Factory;
use Illuminate\Contracts\View\View;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
class SettingsController extends Controller
{
/**
* Display a listing of the resource.
*
* @return Application|Factory|View|Response
*/
public function index()
{
//Get all tabs as laravel view paths
$tabs = [];
foreach (glob(resource_path('views/admin/settings/tabs/*.blade.php')) as $filename) {
$tabs[] = 'admin.settings.tabs.' . basename($filename, '.blade.php');
}
//Generate a html list item for each tab based on tabs file basename, set first tab as active
$tabListItems = [];
foreach ($tabs as $tab) {
$tabName = str_replace('admin.settings.tabs.', '', $tab);
$tabListItems[] = '<li class="nav-item">
<a class="nav-link ' . (empty($tabListItems) ? 'active' : '') . '" data-toggle="pill" href="#' . $tabName . '">
' . __(ucfirst($tabName)) . '
</a></li>';
}
return view('admin.settings.index', [
'tabs' => $tabs,
'tabListItems' => $tabListItems,
2022-01-04 09:03:03 +00:00
]);
2021-06-05 09:26:32 +00:00
}
2021-11-12 17:23:06 +00:00
public function updateIcons(Request $request)
{
2021-06-05 09:26:32 +00:00
$request->validate([
2021-11-12 17:23:06 +00:00
'icon' => 'nullable|max:10000|mimes:jpg,png,jpeg',
'favicon' => 'nullable|max:10000|mimes:ico',
2021-06-05 09:26:32 +00:00
]);
2021-11-12 17:23:06 +00:00
if ($request->hasFile('icon')) {
$request->file('icon')->storeAs('public', 'icon.png');
}
2021-06-05 09:26:32 +00:00
2021-11-12 17:23:06 +00:00
if ($request->hasFile('favicon')) {
$request->file('favicon')->storeAs('public', 'favicon.ico');
}
2021-06-05 09:26:32 +00:00
2021-12-13 10:47:35 +00:00
return redirect()->route('admin.settings.index')->with('success', __('Icons updated!'));
2021-06-05 09:26:32 +00:00
}
2021-11-30 17:40:56 +00:00
public function updateInvoiceSettings(Request $request)
{
$request->validate([
2021-12-01 11:19:06 +00:00
'logo' => 'nullable|max:10000|mimes:jpg,png,jpeg',
2021-11-30 17:40:56 +00:00
]);
2021-12-14 18:50:36 +00:00
InvoiceSettings::updateOrCreate([
'id' => "1"
], [
'company_name' => $request->get('company-name'),
2021-12-16 18:38:25 +00:00
'company_adress' => $request->get('company-address'),
2021-12-14 18:50:36 +00:00
'company_phone' => $request->get('company-phone'),
'company_mail' => $request->get('company-mail'),
'company_vat' => $request->get('company-vat'),
'company_web' => $request->get('company-web'),
'invoice_prefix' => $request->get('invoice-prefix'),
]);
2021-11-30 17:40:56 +00:00
2021-12-01 11:19:06 +00:00
if ($request->hasFile('logo')) {
$request->file('logo')->storeAs('public', 'logo.png');
}
2021-11-30 17:40:56 +00:00
return redirect()->route('admin.settings.index')->with('success', 'Invoice settings updated!');
}
2021-06-05 09:26:32 +00:00
}