Issues (210)

src/Models/Admin/Preference.php (2 issues)

1
<?php
2
3
namespace Pratiksh\Adminetic\Models\Admin;
4
5
use App\Models\User;
0 ignored issues
show
The type App\Models\User 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...
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Support\Facades\Cache;
8
use Spatie\Activitylog\LogOptions;
9
use Spatie\Activitylog\Traits\LogsActivity;
10
11
class Preference extends Model
12
{
13
    use LogsActivity;
0 ignored issues
show
The trait Spatie\Activitylog\Traits\LogsActivity requires some properties which are not provided by Pratiksh\Adminetic\Models\Admin\Preference: $submitEmptyLogs, $name, $logExceptAttributes, $attributeRawValues, $dontLogIfAttributesChangedOnly, $descriptionForEvent, $logOnlyDirty, $logFillable, $value, $logUnguarded, $logAttributes
Loading history...
14
15
    protected $guarded = [];
16
17
    // Forget cache on updating or saving and deleting
18
    public static function boot()
19
    {
20
        parent::boot();
21
22
        static::saving(function () {
23
            self::cacheKey();
24
        });
25
26
        static::deleting(function () {
27
            self::cacheKey();
28
        });
29
    }
30
31
    // Cache Keys
32
    private static function cacheKey()
33
    {
34
        Cache::has('preferences') ? Cache::forget('preferences') : '';
35
    }
36
37
    // Logs
38
    protected static $logName = 'preference';
39
40
    public function getActivitylogOptions(): LogOptions
41
    {
42
        return LogOptions::defaults();
43
    }
44
45
    // Casts
46
    public $casts = [
47
        'roles' => 'array',
48
    ];
49
50
    // Mutators
51
    public function setPreferenceAttribute($value)
52
    {
53
        $this->attributes['preference'] = strtolower(str_replace(' ', '_', $value));
54
    }
55
56
    // Accessors
57
    public function getPreferenceAttribute($value)
58
    {
59
        return ucwords(str_replace('_', ' ', $value));
60
    }
61
62
    // Relation
63
64
    /**
65
     * The users that belong to the Preference.
66
     *
67
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
68
     */
69
    public function users()
70
    {
71
        return $this->belongsToMany(User::class)->withPivot('enabled')->withTimestamps();
72
    }
73
}
74