Completed
Push — master ( 32a7b8...55ace2 )
by wen
02:41
created

AbstractEvent::getContent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
4
namespace Sco\ActionLog\Events;
5
6
use Auth;
7
use Illuminate\Database\Eloquent\Model;
8
9
abstract class AbstractEvent
10
{
11
12
    public $model;
13
14
    public $log;
15
16
    public $type;
17
18
    public function __construct(Model $model)
19
    {
20
        $this->model = $model;
21
        $this->setLogValue();
22
    }
23
24
    public function getContent()
25
    {
26
        return $this->model->getOriginal();
27
    }
28
29
    /**
30
     * Set action log value
31
     */
32
    private function setLogValue()
33
    {
34
        $this->log = [
35
            'user_id' => Auth::id(),
36
            'ip'      => request()->getClientIp(),
37
        ];
38
    }
39
40
    /**
41
     * Get log value
42
     *
43
     * @param null|string $key
44
     * @param mixed       $default
45
     *
46
     * @return mixed
47
     */
48
    public function getLogValue($key = null, $default = null)
49
    {
50
        if (is_null($key)) {
51
            return $this->log;
52
        }
53
54
        return isset($this->log[$key]) ? $this->log[$key] : $default;
55
    }
56
}
57