Total Complexity | 6 |
Total Lines | 49 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
9 | class ContactService extends CRUDServices |
||
10 | { |
||
11 | private Contact $contact; |
||
12 | |||
13 | public function __construct(Contact $contact) |
||
14 | { |
||
15 | if (request()->has('contact_id')) { |
||
16 | $this->contact = Contact::findOrFail(request('contact_id')); |
||
17 | } else { |
||
18 | $this->contact = $contact; |
||
19 | } |
||
20 | } |
||
21 | |||
22 | /** |
||
23 | * Retrieves an instance of contact. |
||
24 | */ |
||
25 | public function getContact(): Contact |
||
26 | { |
||
27 | return $this->contact; |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * Makes a list of fields that you do not want to be sent |
||
32 | * to the create or update methods. |
||
33 | * Its mainly the fields that you do not have in the contacts table. |
||
34 | */ |
||
35 | public function getUnsetFields() |
||
36 | { |
||
37 | return ['contact_id']; |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * This returns the model found in the constructor |
||
42 | * or an instance of the class if no contact is found. |
||
43 | */ |
||
44 | public function getModel() |
||
45 | { |
||
46 | return $this->getContact(); |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * Attaches a parent to the current contact |
||
51 | * You can delete this if you do not intent to create contacts from parent relationships. |
||
52 | */ |
||
53 | public function getParentRelationship() |
||
58 | ]; |
||
59 | } |
||
60 | } |
||
61 |