This repository has been archived on 2025-12-04. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Caramel-CRM-Backup/app/Http/Controllers/ContactController.php
T
vollstock 8703e5ff40
linter / quality (push) Has been cancelled
tests / ci (push) Has been cancelled
Add initial Code
2025-10-20 08:57:51 +02:00

54 lines
1.8 KiB
PHP

<?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,
'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,
'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,
];
}
}