Files
Caramel-CRM/app/Http/Controllers/ContactController.php
T

57 lines
1.9 KiB
PHP
Raw Normal View History

2025-10-20 08:57:51 +02:00
<?php
namespace App\Http\Controllers;
use App\Models\Contact;
class ContactController extends Controller
{
public function index()
{
return Contact::with('customer')->get()->map(function ($contact) {
return [
'id' => $contact->id,
'customerId' => $contact->customer_id,
2025-10-29 13:53:08 +01:00
'salutation' => $contact->salutation,
2025-10-20 08:57:51 +02:00
'firstName' => $contact->first_name,
'lastName' => $contact->last_name,
'email' => $contact->email,
'phone' => $contact->phone,
'position' => $contact->position,
'isPrimary' => $contact->is_primary,
'avatar' => $contact->avatar,
'customer' => $contact->customer ? [
'id' => $contact->customer->id,
'companyName' => $contact->customer->company_name,
'email' => $contact->customer->email,
'phone' => $contact->customer->phone,
] : null,
];
});
}
public function show($id)
{
$contact = Contact::with('customer')->findOrFail($id);
return [
'id' => $contact->id,
'customerId' => $contact->customer_id,
2025-10-29 13:53:08 +01:00
'salutation' => $contact->salutation,
2025-10-20 08:57:51 +02:00
'firstName' => $contact->first_name,
'lastName' => $contact->last_name,
'email' => $contact->email,
'phone' => $contact->phone,
'position' => $contact->position,
'isPrimary' => $contact->is_primary,
'avatar' => $contact->avatar,
'customer' => $contact->customer ? [
'id' => $contact->customer->id,
'companyName' => $contact->customer->company_name,
'email' => $contact->customer->email,
'phone' => $contact->customer->phone,
] : null,
];
}
2025-10-29 13:53:08 +01:00
}