Completed
Push — master ( 8131b6...c9ac78 )
by Marcel
09:22 queued 05:21
created

Webhook::logs()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
namespace Mpociot\CaptainHook;
3
4
use Illuminate\Database\Eloquent\Model as Eloquent;
5
use Illuminate\Support\Facades\Cache;
6
7
/**
8
 * This file is part of CaptainHook arrrrr
9
 *
10
 * @license MIT
11
 * @package CaptainHook
12
 */
13
class Webhook extends Eloquent
14
{
15
    /**
16
     * Cache key to use to store loaded webhooks
17
     */
18
    const CACHE_KEY = 'mpociot.captainhook.hooks';
19
20
    /**
21
     * Make all fields fillable
22
     * @var array
23
     */
24
    public $fillable = ['id', 'url', 'event', 'tenant_id'];
25
26
27
    /**
28
     * Boot the model
29
     * Whenever a new Webhook get's created the cache get's cleared
30
     */
31
    public static function boot()
32
    {
33
        parent::boot();
34
35
        static::created(function ($results) {
0 ignored issues
show
Unused Code introduced by
The parameter $results is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
36
            Cache::forget(self::CACHE_KEY);
37
        });
38
39
        static::deleted(function ($results) {
0 ignored issues
show
Unused Code introduced by
The parameter $results is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
40
            Cache::forget(self::CACHE_KEY);
41
        });
42
    }
43
44
    /**
45
     * Retrieve the logs for a given hook.
46
     *
47
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
48
     */
49
    public function logs()
50
    {
51
        return $this->hasMany(WebhookLog::class);
52
    }
53
}
54