dealhub/app/Http/Controllers/Admin/CustomerController.php
kusowl c087126080 feature(admin-panel): manage broker section
- admin can edit, approve or reject broker registration
- admin can edit, delete or impersonate as broker
2026-01-28 13:44:05 +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.');
}
}
}