140 lines
6.4 KiB
PHP
140 lines
6.4 KiB
PHP
<?php
|
|
|
|
use App\Http\Controllers\ProductController;
|
|
use App\Http\Controllers\VendingMachineController;
|
|
use App\Http\Controllers\SlotController;
|
|
use App\Http\Controllers\VendingDisplayController;
|
|
use App\Http\Controllers\SettingsController;
|
|
use App\Http\Controllers\TenantController;
|
|
use App\Http\Controllers\UserController;
|
|
use Illuminate\Support\Facades\Route;
|
|
|
|
// Auth-Routen
|
|
Auth::routes();
|
|
|
|
// Mandanten-Auswahl (nur für eingeloggte Benutzer)
|
|
Route::middleware(['auth'])->group(function () {
|
|
Route::get('/tenants', [TenantController::class, 'select'])->name('tenants.select');
|
|
Route::get('/tenants/{tenant}/switch', [TenantController::class, 'switch'])->name('tenants.switch');
|
|
Route::match(['GET', 'POST'], '/tenants/leave', [TenantController::class, 'leave'])->name('tenants.leave');
|
|
|
|
// Mandanten-Verwaltung (nur für Super-Admins)
|
|
Route::prefix('admin')->name('admin.')->group(function () {
|
|
Route::resource('tenants', TenantController::class)->except(['show']);
|
|
});
|
|
});
|
|
|
|
// Admin-Bereich (geschützt)
|
|
Route::middleware(['auth', 'tenant.scope', 'tenant.session'])->prefix('admin')->group(function () {
|
|
Route::get('/', function () {
|
|
$user = auth()->user();
|
|
|
|
// Super-Admin ohne gewählten Mandanten → zur Auswahl
|
|
if ($user->isSuperAdmin() && !session('current_tenant_id')) {
|
|
return redirect()->route('tenants.select');
|
|
}
|
|
|
|
return view('admin.dashboard');
|
|
})->name('admin.dashboard');
|
|
|
|
Route::resource('products', ProductController::class);
|
|
Route::resource('vending-machines', VendingMachineController::class);
|
|
Route::get('vending-machines/{id}/qr-code', [VendingMachineController::class, 'generateQrCode'])->name('vending-machines.qr-code');
|
|
Route::resource('slots', SlotController::class);
|
|
|
|
// Benutzerverwaltung (nur für Super Admins)
|
|
Route::resource('users', UserController::class)->names([
|
|
'index' => 'admin.users.index',
|
|
'create' => 'admin.users.create',
|
|
'store' => 'admin.users.store',
|
|
'show' => 'admin.users.show',
|
|
'edit' => 'admin.users.edit',
|
|
'update' => 'admin.users.update',
|
|
'destroy' => 'admin.users.destroy'
|
|
]);
|
|
|
|
// Einstellungen
|
|
Route::get('settings', [SettingsController::class, 'index'])->name('admin.settings.index');
|
|
Route::put('settings', [SettingsController::class, 'update'])->name('admin.settings.update');
|
|
|
|
// Mandanten-spezifische Einstellungen
|
|
Route::get('settings/tenant', [SettingsController::class, 'tenantSettings'])->name('admin.settings.tenant');
|
|
Route::put('settings/tenant', [SettingsController::class, 'updateTenantSettings'])->name('admin.settings.tenant.update');
|
|
|
|
// Zusätzliche Routen für Slot-Produkt-Zuordnung
|
|
Route::post('slots/{slot}/products/{product}', [SlotController::class, 'attachProduct'])->name('slots.attach-product');
|
|
Route::delete('slots/{slot}/products/{product}', [SlotController::class, 'detachProduct'])->name('slots.detach-product');
|
|
Route::put('slots/{slot}/products/{product}', [SlotController::class, 'updateProduct'])->name('slots.update-product');
|
|
});
|
|
|
|
// Debug-Routen (außerhalb der Admin-Gruppe für einfacheres Testing)
|
|
Route::get('debug/session', function(\Illuminate\Http\Request $request) {
|
|
$user = auth()->user();
|
|
return response()->json([
|
|
'authenticated' => auth()->check(),
|
|
'user_id' => $user ? $user->id : null,
|
|
'user_email' => $user ? $user->email : null,
|
|
'is_super_admin' => $user ? $user->isSuperAdmin() : null,
|
|
'user_tenant_id' => $user ? $user->tenant_id : null,
|
|
'session_tenant_id' => session('current_tenant_id'),
|
|
'session_tenant' => session('current_tenant'),
|
|
'all_session' => session()->all()
|
|
]);
|
|
})->name('debug.session');
|
|
|
|
// Test-Route für Form-Submit ohne Middleware
|
|
Route::post('debug/tenant-test', function(\Illuminate\Http\Request $request) {
|
|
\Log::info('DEBUG: Test Route erreicht!', [
|
|
'method' => $request->method(),
|
|
'data' => $request->all(),
|
|
'show_prices_has' => $request->has('show_prices'),
|
|
'show_stock_has' => $request->has('show_stock')
|
|
]);
|
|
|
|
return response()->json([
|
|
'status' => 'success',
|
|
'message' => 'Test Route erreicht!',
|
|
'show_prices' => $request->has('show_prices'),
|
|
'show_stock' => $request->has('show_stock')
|
|
]);
|
|
});
|
|
|
|
// Debug Settings Route (mit vollem Admin-Middleware aber eigenem Controller)
|
|
Route::middleware(['web', 'auth'])->group(function () {
|
|
Route::get('debug/settings/tenant', function() {
|
|
return view('debug.tenant-settings');
|
|
})->name('debug.settings.tenant');
|
|
Route::put('debug/settings/tenant', [\App\Http\Controllers\DebugSettingsController::class, 'updateTenantSettings'])->name('debug.settings.tenant.update');
|
|
});
|
|
|
|
// Test: Original Settings ohne Middleware für Debug
|
|
Route::get('test/tenant-settings', [\App\Http\Controllers\SettingsController::class, 'tenantSettings'])->name('test.tenant.settings');
|
|
|
|
// Einfacher Test um zu prüfen ob Routen grundsätzlich funktionieren
|
|
Route::get('test/simple', function() {
|
|
\Log::info('Simple Test Route erreicht!');
|
|
return 'Simple Test funktioniert - siehe Log';
|
|
});
|
|
|
|
// Alte Routen entfernt - werden durch neue öffentliche Routen ersetzt
|
|
|
|
// Home-Route
|
|
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
|
|
|
|
// Öffentliche Snackautomat-Anzeige (Hauptseite)
|
|
Route::get('/', [VendingDisplayController::class, 'index'])->name('vending.index');
|
|
|
|
// Mandanten-Übersicht
|
|
Route::get('/mandanten', [VendingDisplayController::class, 'tenantsOverview'])->name('vending.tenants');
|
|
|
|
// Globale Produkt-/Slot-Routen (ohne Mandant)
|
|
Route::get('/product/{product}', [VendingDisplayController::class, 'showProduct'])->name('vending.product');
|
|
Route::get('/machine/{machine}/slot/{slot}', [VendingDisplayController::class, 'showSlot'])->name('vending.slot');
|
|
|
|
// Mandantenspezifische Produkt-Routen
|
|
Route::get('/{publicSlug}/product/{product}', [VendingDisplayController::class, 'showProductByTenant'])->name('vending.tenant.product');
|
|
|
|
// Vereinheitlichte mandantenspezifische URLs (verwenden public_slug)
|
|
Route::get('/{publicSlug}/maschine/{machineNumber}', [VendingDisplayController::class, 'showMachineByPublicSlug'])->name('vending.public.machine');
|
|
Route::get('/{publicSlug}', [VendingDisplayController::class, 'indexByPublicSlug'])->name('vending.public.tenant');
|