# Media URL in Response - Example

## ✅ What Changed

Updated both `ProfileUpdateRequestDetailsResource` files to convert media IDs to full media objects with URLs.

## 📊 Response Format

### Before (Media ID Only)
```json
{
  "id": 1,
  "profile_data": {
    "logo": "fb9dcbd8-7c3c-4432-91a6-c7c2277b4bfa",
    "commercial_register_file": "abc123-def456-uuid",
    "commercial_register_number": "CR-2024-123456",
    "translations": {
      "ar": {
        "name": "متجر الإلكترونيات",
        "description": "وصف المتجر"
      },
      "en": {
        "name": "Electronics Store",
        "description": "Store description"
      }
    }
  },
  "status": "pending"
}
```

### After (Media Object with URL)
```json
{
  "id": 1,
  "profile_data": {
    "logo": {
      "id": "fb9dcbd8-7c3c-4432-91a6-c7c2277b4bfa",
      "path": "https://yourdomain.com/storage/images/logo_fb9dcbd8.jpg",
      "type": "image",
      "name": "logo_fb9dcbd8.jpg"
    },
    "commercial_register_file": {
      "id": "abc123-def456-uuid",
      "path": "https://yourdomain.com/storage/files/register_abc123.pdf",
      "type": "pdf",
      "name": "register_abc123.pdf"
    },
    "commercial_register_number": "CR-2024-123456",
    "translations": {
      "ar": {
        "name": "متجر الإلكترونيات",
        "description": "وصف المتجر"
      },
      "en": {
        "name": "Electronics Store",
        "description": "Store description"
      }
    }
  },
  "location_data": {
    "country_id": 1,
    "city_id": 5,
    "lat": 24.7136,
    "lng": 46.6753,
    "name": "Main Branch",
    "property_number": "1234",
    "details": "Building details",
    "url": "https://maps.google.com/?q=24.7136,46.6753"
  },
  "status": "pending",
  "admin_note": null,
  "created_at": "2026-04-20 12:30:45",
  "updated_at": "2026-04-20 12:30:45"
}
```

## 🔧 How It Works

### Resource Method
```php
private function formatProfileData($profileData)
{
    if (!$profileData) {
        return null;
    }

    $formatted = $profileData;

    // Convert logo ID to media object with URL
    if (isset($profileData['logo'])) {
        $formatted['logo'] = $this->getMediaData($profileData['logo']);
    }

    // Convert commercial_register_file ID to media object with URL
    if (isset($profileData['commercial_register_file'])) {
        $formatted['commercial_register_file'] = $this->getMediaData($profileData['commercial_register_file']);
    }

    return $formatted;
}

private function getMediaData($mediaId)
{
    if (!$mediaId) {
        return null;
    }

    $media = Media::find($mediaId);

    if (!$media) {
        return null;
    }

    return [
        'id'   => $media->id,
        'path' => asset('storage/' . trim($media->path, '/') . '/' . $media->name),
        'type' => $media->type,
        'name' => $media->name,
    ];
}
```

## 📁 Files Updated

1. ✅ `app/Http/Resources/Api/Dashboard/Admin/ProfileUpdateRequest/ProfileUpdateRequestDetailsResource.php`
2. ✅ `app/Http/Resources/Api/Dashboard/Vendor/ProfileUpdateRequest/ProfileUpdateRequestDetailsResource.php`

## 🎯 Benefits

1. **Frontend Ready** - URL is directly usable in `<img>` tags
2. **Complete Info** - Includes ID, path, type, and name
3. **Consistent** - Matches the format used by Profile model's MediaTrait
4. **Null Safe** - Handles missing media gracefully

## 📝 Usage in Frontend

### Display Logo
```javascript
// React/Vue example
<img src={profileData.logo.path} alt="Logo" />

// Check if logo exists
{profileData.logo && (
  <img src={profileData.logo.path} alt="Logo" />
)}
```

### Display Commercial Register File
```javascript
// PDF viewer or download link
<a href={profileData.commercial_register_file.path} target="_blank">
  View Commercial Register
</a>
```

## 🔍 Admin View - Additional Info

Admin resource also includes `current_profile` for comparison:

```json
{
  "id": 1,
  "vendor": {
    "id": 10,
    "name": "Vendor Name",
    "email": "vendor@example.com",
    "logo": {
      "id": "old-logo-id",
      "path": "https://domain.com/storage/images/old_logo.jpg",
      "type": "image"
    }
  },
  "profile_data": {
    "logo": {
      "id": "new-logo-id",
      "path": "https://domain.com/storage/images/new_logo.jpg",
      "type": "image"
    }
  },
  "current_profile": {
    "logo": {
      "id": "old-logo-id",
      "path": "https://domain.com/storage/images/old_logo.jpg",
      "type": "image"
    },
    "commercial_register_number": "CR-OLD-123",
    "translations": [...]
  }
}
```

This allows admin to compare:
- **Old logo** (current_profile.logo)
- **New logo** (profile_data.logo)

## ✅ Ready to Use

The media URLs are now automatically included in all show/details responses for profile update requests!
