54 lines
1.8 KiB
PHP
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,
|
||
|
|
];
|
||
|
|
}
|
||
|
|
}
|