feat: 🎨 Moved Settingscontroller to their own directory
This commit is contained in:
parent
0a75de9689
commit
cd91931bc0
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin\SettingsControllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\InvoiceSettings;
|
||||
use Illuminate\Http\Request;
|
||||
use ZipArchive;
|
||||
|
||||
class InvoiceSettingsController extends Controller
|
||||
{
|
||||
public $tabTitle = 'Invoice Settings';
|
||||
public $invoiceSettings;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->invoiceSettings = InvoiceSettings::first();
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return view('admin.settings.tabs.invoice', [
|
||||
'invoiceSettings' => $this->invoiceSettings,
|
||||
]);
|
||||
}
|
||||
|
||||
public function updateInvoiceSettings(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'logo' => 'nullable|max:10000|mimes:jpg,png,jpeg',
|
||||
]);
|
||||
|
||||
InvoiceSettings::updateOrCreate([
|
||||
'id' => "1"
|
||||
], [
|
||||
'company_name' => $request->get('company-name'),
|
||||
'company_adress' => $request->get('company-address'),
|
||||
'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'),
|
||||
]);
|
||||
|
||||
if ($request->hasFile('logo')) {
|
||||
$request->file('logo')->storeAs('public', 'logo.png');
|
||||
}
|
||||
|
||||
|
||||
return redirect()->route('admin.settings.index')->with('success', 'Invoice settings updated!');
|
||||
}
|
||||
|
||||
public function downloadAllInvoices()
|
||||
{
|
||||
$zip = new ZipArchive;
|
||||
$zip_safe_path = storage_path('invoices.zip');
|
||||
$res = $zip->open($zip_safe_path, ZipArchive::CREATE | ZipArchive::OVERWRITE);
|
||||
$result = $this::rglob(storage_path('app/invoice/*'));
|
||||
if ($res === TRUE) {
|
||||
$zip->addFromString("1. Info.txt", "This Archive contains all Invoices from all Users!\nIf there are no Invoices here, no Invoices have ever been created!");
|
||||
foreach ($result as $file) {
|
||||
if (file_exists($file) && is_file($file)) {
|
||||
$zip->addFile($file, basename($file));
|
||||
}
|
||||
}
|
||||
$zip->close();
|
||||
}
|
||||
return response()->download($zip_safe_path);
|
||||
}
|
||||
|
||||
public function rglob($pattern, $flags = 0)
|
||||
{
|
||||
$files = glob($pattern, $flags);
|
||||
foreach (glob(dirname($pattern) . '/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir) {
|
||||
$files = array_merge($files, $this::rglob($dir . '/' . basename($pattern), $flags));
|
||||
}
|
||||
return $files;
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
namespace App\Http\Controllers\Admin\SettingsControllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\InvoiceSettings;
|
||||
|
@ -20,10 +20,25 @@ class SettingsController extends Controller
|
|||
*/
|
||||
public function index()
|
||||
{
|
||||
/** @var InvoiceSettings $invoiceSettings */
|
||||
$invoiceSettings = InvoiceSettings::first();
|
||||
//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');
|
||||
}
|
||||
|
||||
return view('admin.settings.index', $invoiceSettings->toArray());
|
||||
// <li class="nav-item">
|
||||
// <a class="nav-link" data-toggle="pill" href="#invoice">{{ __('Invoice Settings2') }}</a>
|
||||
// </li>
|
||||
|
||||
//Generate a html list item for each tab based on tabs file basename
|
||||
$tabsListItem = [];
|
||||
foreach ($tabs as $tab) {
|
||||
$tabsListItem[] = '<li class="nav-item"><a class="nav-link" href="' . route('admin.settings.index', ['tab' => $tab]) . '">' . str_replace('_', ' ', ucfirst(basename($tab, '.blade.php'))) . '</a></li>';
|
||||
}
|
||||
|
||||
return view('admin.settings.index', [
|
||||
'tabs' => $tabs,
|
||||
]);;
|
||||
}
|
||||
|
||||
public function updateIcons(Request $request)
|
||||
|
@ -96,5 +111,4 @@ class SettingsController extends Controller
|
|||
}
|
||||
return $files;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue