Issues (56)

src/Models/Admin/Contact.php (1 issue)

Labels
Severity
1
<?php
2
3
namespace Adminetic\Contact\Models\Admin;
4
5
use Illuminate\Support\Facades\Cache;
6
use Illuminate\Database\Eloquent\Model;
7
use Adminetic\Contact\Models\Admin\Group;
8
use Spatie\Activitylog\Traits\LogsActivity;
0 ignored issues
show
The type Spatie\Activitylog\Traits\LogsActivity was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
10
class Contact extends Model
11
{
12
    use LogsActivity;
13
14
    protected $guarded = [];
15
16
    // Forget cache on updating or saving and deleting
17
    public static function boot()
18
    {
19
        parent::boot();
20
21
        static::saving(function () {
22
            self::cacheKey();
23
        });
24
25
        static::deleting(function () {
26
            self::cacheKey();
27
        });
28
    }
29
30
    // Cache Keys
31
    private static function cacheKey()
32
    {
33
        Cache::has('contacts') ? Cache::forget('contacts') : '';
34
    }
35
36
    // Logs
37
    protected static $logName = 'contact';
38
39
    // Scopes
40
    public function scopeActive($query)
41
    {
42
        return $query->where('active', 1);
43
    }
44
    public function scopeInActive($query)
45
    {
46
        return $query->where('active', 0);
47
    }
48
    public function scopeFavorite($query)
49
    {
50
        return $query->where('favorite', 1);
51
    }
52
    public function scopeNonFavorite($query)
53
    {
54
        return $query->where('favorite', 0);
55
    }
56
57
    // Relations
58
    public function groups()
59
    {
60
        return $this->belongsToMany(Group::class)->withTimestamps();
61
    }
62
}
63