dealhub/app/Http/Controllers/Admin/CustomerController.php
kusowl 690a50408d feature(admin-panel): add manage customer page
- list customer
- edit customer details
- delete customer
2026-01-27 17:18:50 +05:30

60 lines
1.9 KiB
PHP

<?php
namespace App\Http\Controllers\Admin;
use App\Actions\UpdateCustomerAction;
use App\Http\Controllers\Controller;
use App\Http\Requests\StoreCustomerProfileRequest;
use App\Models\Customer;
use Illuminate\Support\Facades\Log;
class CustomerController extends Controller
{
public function index()
{
return view('dashboards.admin.customers.index')
->with('customers', Customer::select(['id', 'location'])
->with('user:id,name,email,role_id,role_type')
->get()
);
}
public function edit(Customer $customer)
{
return view('dashboards.admin.customers.edit')
->with('profile', $customer->user)
->with('backLink', route('admin.customers.index'))
->with('actionLink', route('admin.customers.update', $customer));
}
public function update(StoreCustomerProfileRequest $request, Customer $customer, UpdateCustomerAction $action)
{
try {
$action->execute($request->validated(), $customer->user);
return to_route('admin.customers.index')
->with('success', 'Profile updated successfully.');
} catch (\Throwable $e) {
Log::error('Customer Profile Update Failed: '.$e->getMessage(), $e->getTrace());
return back()->withInput()->with('error', 'Something went wrong.');
}
}
public function destroy(Customer $customer)
{
try {
\DB::transaction(function () use ($customer) {
$customer->user->delete();
$customer->delete();
});
return back()->with('success', 'Customer deleted successfully.');
} catch (\Throwable $e) {
Log::error('Customer Delete Failed: '.$e->getMessage(), $e->getTrace());
return back()->with('error', 'Something went wrong.');
}
}
}