ApiLog::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
namespace Sarahman\HttpRequestApiLog\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Sarahman\HttpRequestApiLog\Helper;
7
8
/**
9
 * This model deals with Http API calls logging.
10
 *
11
 * @property int                 $id
12
 * @property string              $client
13
 * @property string              $method
14
 * @property string              $endpoint
15
 * @property string              $params
16
 * @property int|null            $response_code
17
 * @property string|null         $response
18
 * @property \Carbon\Carbon|null $created_at
19
 * @property \Carbon\Carbon|null $updated_at
20
 */
21
class ApiLog extends Model
22
{
23
    /**
24
     * @inheritDoc
25
     */
26
    protected $guarded = [];
27
28
    public function __construct(array $attributes = [])
29
    {
30
        $config = Helper::getConfig();
31
32
        isset($this->connection) || $this->setConnection($config['database_connection']);
33
        isset($this->table) || $this->setTable($config['table_name']);
34
35
        parent::__construct($attributes);
36
    }
37
38
    /**
39
     * @inheritDoc
40
     */
41
    protected static function boot()
42
    {
43
        parent::boot();
44
45
        self::creating(function (self $model) {
46
            $model->method = strtoupper($model->method);
47
            $model->params = json_encode($model->params);
48
        });
49
    }
50
}
51