Files
WitShop/app/Http/Controllers/Admin/CustomerController.php
T
marcoandClaude Sonnet 4.6 41078fdc08 Initial commit: WitShop Laravel Online-Shop
- Laravel 11, Blade, Alpine.js, Tailwind CSS
- Produkt- & Kategorieverwaltung mit Varianten
- Checkout (Vorkasse + Rechnung), Session-Warenkorb
- Admin-Backend (Dashboard, Bestellungen, Kunden, CMS)
- DSGVO-konform: Cookie-Consent, Impressum, Widerruf, AGB
- PDF-Rechnung via dompdf, SMTP-Mailversand
- Kundenverwaltung mit manueller Freischaltung

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-20 00:34:09 +02:00

75 lines
2.2 KiB
PHP

<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Http\Request;
class CustomerController extends Controller
{
public function index(Request $request)
{
$query = User::where('role', 'customer')->withCount('orders');
if ($request->filled('q')) {
$query->where(function ($q) use ($request) {
$q->where('name', 'like', '%'.$request->q.'%')
->orWhere('email', 'like', '%'.$request->q.'%');
});
}
$customers = $query->latest()->paginate(25);
return view('admin.customers.index', compact('customers'));
}
public function show(User $customer)
{
abort_if($customer->isAdmin(), 404);
$customer->load('addresses');
$orders = $customer->orders()
->with('addresses')
->latest()
->paginate(15);
$stats = [
'total_orders' => $customer->orders()->count(),
'total_revenue' => $customer->orders()
->whereNotIn('status', ['cancelled'])
->sum('total'),
'open_orders' => $customer->orders()
->whereIn('status', ['new', 'payment_received', 'processing'])
->count(),
'last_order' => $customer->orders()->latest()->first(),
];
return view('admin.customers.show', compact('customer', 'orders', 'stats'));
}
public function toggleApproval(User $customer)
{
abort_if($customer->isAdmin(), 403);
$approving = ! $customer->approved;
$customer->approved = $approving;
if ($approving && ! $customer->email_verified_at) {
$customer->email_verified_at = now();
}
$customer->save();
$status = $approving ? 'freigeschaltet' : 'gesperrt';
return back()->with('success', "Kunde {$customer->name} wurde {$status}.");
}
public function destroy(User $customer)
{
abort_if($customer->isAdmin(), 403);
$customer->delete();
return redirect()->route('admin.customers.index')->with('success', 'Kunde gelöscht.');
}
}