# Quick Guide: Update Client Information

## Summary

Your Laravel Radius Circle application has **TWO main tables** for client data:

1. **`clients`** - Main authentication & billing data (60+ columns)
2. **`clientsinfo`** - Personal & address details (50+ columns)

**Note:** There is **NO `select_client` table** in your database. You likely mean the `clients` table.

---

## Quick Column Reference

### `clients` Table - Key Columns
```
✓ id, pop_id, billing_cycle, package_id
✓ userid (unique), password, mac, ip_address
✓ expire_date, clients_status, client_approval
✓ customer_id, customer_code, customer_type
✓ payment_dadeline, parmanent_discount
✓ bandwidth_limit, apply_bandwidth_limit
✓ marketed_by, box_id, line_man_id
✓ is_free, remote_access, ipv6
✓ created_by, created_at, updated_at, deleted_at
```

### `clientsinfo` Table - Key Columns
```
✓ id, client_id (FK to clients.id)
✓ clients_name, father_name, mother_name
✓ contact_no, other_contact, email
✓ national_id, passport_no, dob
✓ flat_no, building_name, building_no
✓ road_name, road_no, block_sector
✓ area, division, district, upazila, thana
✓ owner_name, owner_number
✓ olt_pon, olt_no, pon_port, onu_serial
✓ cable_type, cat_type, cat_length
✓ from_cable, to_cable, cable_id
✓ joinDate, remarks, box, box_id
✓ client_latitude, client_longitude
✓ profilePicture, customer_agrement
✓ created_at, updated_at
```

---

## How to Update - Code Examples

### Option 1: Using ClientServices (RECOMMENDED ✅)

```php
use App\Services\ClientServices;

// In your controller's update method
public function update(Request $request, $id)
{
    $client = Client::findOrFail($id);
    
    // This updates BOTH clients and clientsinfo tables
    ClientServices::clientUpdate($request, $client);
    
    return redirect()->back()->with('success', 'Client updated!');
}
```

**This is the method used in:** `app/Http/Controllers/ClientController.php` line 1553

---

### Option 2: Manual Update (Both Tables)

```php
use App\Models\Client;
use Illuminate\Support\Facades\DB;

public function update(Request $request, $id)
{
    DB::beginTransaction();
    
    try {
        // Update clients table
        $client = Client::findOrFail($id);
        $client->userid = $request->userid;
        $client->password = $request->password;
        $client->pop_id = $request->pop_id;
        $client->package_id = $request->package_id;
        $client->mac = $request->mac;
        $client->ip_address = $request->ip_address;
        $client->payment_dadeline = $request->payment_dadeline;
        $client->customer_code = $request->customer_code;
        $client->save();
        
        // Update clientsinfo table
        DB::table('clientsinfo')
            ->updateOrInsert(
                ['client_id' => $client->id],
                [
                    'clients_name' => $request->client_name,
                    'father_name' => $request->father_name,
                    'contact_no' => $request->contact_no,
                    'email' => $request->email,
                    'national_id' => $request->national_id,
                    'flat_no' => $request->flat_no,
                    'building_name' => $request->building_name,
                    'road_no' => $request->road_no,
                    'area' => $request->area,
                    'district' => $request->district,
                    'thana' => $request->thana,
                    'remarks' => $request->remarks,
                    'updated_at' => now(),
                ]
            );
        
        DB::commit();
        return redirect()->back()->with('success', 'Updated!');
        
    } catch (\Exception $e) {
        DB::rollback();
        return redirect()->back()->with('error', $e->getMessage());
    }
}
```

---

### Option 3: Using Eloquent Relationships

```php
use App\Models\Client;

public function update(Request $request, $id)
{
    $client = Client::with('clientsinfo')->findOrFail($id);
    
    // Update clients table
    $client->update([
        'userid' => $request->userid,
        'password' => $request->password,
        'pop_id' => $request->pop_id,
        'mac' => $request->mac,
        // ... more fields
    ]);
    
    // Update clientsinfo table
    if ($client->clientsinfo) {
        $client->clientsinfo->update([
            'clients_name' => $request->client_name,
            'contact_no' => $request->contact_no,
            'email' => $request->email,
            // ... more fields
        ]);
    } else {
        // Create if doesn't exist
        Clientsinfo::create([
            'client_id' => $client->id,
            'clients_name' => $request->client_name,
            'contact_no' => $request->contact_no,
            // ... more fields
        ]);
    }
    
    return redirect()->back()->with('success', 'Updated!');
}
```

---

## Database Queries

### Get client with all info:
```sql
SELECT c.*, ci.* 
FROM clients c 
LEFT JOIN clientsinfo ci ON c.id = ci.client_id 
WHERE c.id = 123;
```

### Update client main info:
```sql
UPDATE clients 
SET 
    userid = 'user123',
    password = 'pass123',
    pop_id = 5,
    package_id = 10,
    mac = '00:11:22:33:44:55',
    customer_code = 'CUST001'
WHERE id = 123;
```

### Update client additional info:
```sql
UPDATE clientsinfo 
SET 
    clients_name = 'John Doe',
    contact_no = '01712345678',
    email = 'john@example.com',
    area = 'Dhanmondi',
    district = 'Dhaka'
WHERE client_id = 123;
```

---

## Important Files

| File | Purpose |
|------|---------|
| `app/Services/ClientServices.php` | Main update logic (line 33-222) |
| `app/Http/Controllers/ClientController.php` | Controller handling updates (line 1405+) |
| `app/Models/Client.php` | Client model |
| `app/Models/Clientsinfo.php` | Clientsinfo model |
| `database/schema/mysql-schema.dump` | Complete database schema |

---

## Relationship

```
clients (1) ←→ (1) clientsinfo
   ↑                    ↓
  id              client_id (FK)
```

The `clientsinfo.client_id` is a foreign key that references `clients.id`.

---

## Common Update Fields

**For Authentication:**
- userid, password, mac, ip_address

**For Billing:**
- package_id, billing_cycle, expire_date, payment_dadeline

**For Personal Info:**
- clients_name, contact_no, email, national_id

**For Address:**
- flat_no, building_name, road_no, area, district, thana

**For Network:**
- olt_pon, olt_no, pon_port, onu_serial, cable_type

---

## Need More Details?

See the complete reference: `CLIENT_TABLES_COLUMNS_REFERENCE.md`

This file contains:
- ✓ All 60+ columns in `clients` table
- ✓ All 50+ columns in `clientsinfo` table
- ✓ Data types and descriptions
- ✓ Complete code examples
- ✓ SQL queries

---

Generated: 2026-01-29
