MessageService::getModel()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace FaithGen\Messages;
4
5
use FaithGen\Messages\Models\Message;
6
use InnoFlash\LaraStart\Services\CRUDServices;
7
8
class MessageService extends CRUDServices
9
{
10
    /**
11
     * @var Message
12
     */
13
    private $message;
14
15
    public function __construct(Message $message)
16
    {
17
        if (request()->has('message_id')) {
18
            $this->message = Message::findOrFail(request('message_id'));
19
        } else {
20
            $this->message = $message;
21
        }
22
    }
23
24
    /**
25
     * @return Message
26
     */
27
    public function getMessage(): Message
28
    {
29
        return $this->message;
30
    }
31
32
    /**
33
     * This sets the attributes to be removed from the given set for updating or creating.
34
     * @return mixed
35
     */
36
    public function getUnsetFields()
37
    {
38
        return 'message_id';
39
    }
40
41
    /**
42
     * This get the model value or class of the model in the service.
43
     * @return mixed
44
     */
45
    public function getModel()
46
    {
47
        return $this->getMessage();
48
    }
49
50
    public function getParentRelationship()
51
    {
52
        return auth()->user()->messages();
53
    }
54
}
55