1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Adminetic\Website\Models\Admin; |
4
|
|
|
|
5
|
|
|
use App\Models\User; |
|
|
|
|
6
|
|
|
use Illuminate\Database\Eloquent\Model; |
7
|
|
|
use Illuminate\Database\Eloquent\Relations\MorphTo; |
8
|
|
|
use Illuminate\Support\Facades\Cache; |
9
|
|
|
use Spatie\Activitylog\LogOptions; |
|
|
|
|
10
|
|
|
use Spatie\Activitylog\Traits\LogsActivity; |
|
|
|
|
11
|
|
|
|
12
|
|
|
class Payment extends Model |
13
|
|
|
{ |
14
|
|
|
use LogsActivity; |
15
|
|
|
|
16
|
|
|
protected $guarded = []; |
17
|
|
|
|
18
|
|
|
// Forget cache on updating or saving and deleting |
19
|
|
|
public static function boot() |
20
|
|
|
{ |
21
|
|
|
parent::boot(); |
22
|
|
|
|
23
|
|
|
static::saving(function () { |
24
|
|
|
self::cacheKey(); |
25
|
|
|
}); |
26
|
|
|
|
27
|
|
|
static::deleting(function () { |
28
|
|
|
self::cacheKey(); |
29
|
|
|
}); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
// Cache Keys |
33
|
|
|
private static function cacheKey() |
34
|
|
|
{ |
35
|
|
|
Cache::has('payments') ? Cache::forget('payments') : ''; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
// Logs |
39
|
|
|
protected static $logName = 'payment'; |
40
|
|
|
|
41
|
|
|
public function getActivitylogOptions(): LogOptions |
42
|
|
|
{ |
43
|
|
|
return LogOptions::defaults(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
protected $fillable = ['particular', 'amount', 'type', 'paymentable_type']; |
47
|
|
|
|
48
|
|
|
public function __construct(array $attributes = []) |
49
|
|
|
{ |
50
|
|
|
$this->table = config('website.table_prefix', 'website') . '_payments'; |
51
|
|
|
|
52
|
|
|
parent::__construct($attributes); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
public function paymentable(): MorphTo |
57
|
|
|
{ |
58
|
|
|
return $this->morphTo(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
// Accessors |
62
|
|
|
public function getTypeAttribute($attribute) |
63
|
|
|
{ |
64
|
|
|
return in_array($attribute ?? null, [1, 2]) |
65
|
|
|
? [ |
66
|
|
|
1 => 'Income', |
67
|
|
|
2 => 'Expense', |
68
|
|
|
][$attribute] |
69
|
|
|
: null; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
// Helper Method |
73
|
|
|
public function getTypeColor() |
74
|
|
|
{ |
75
|
|
|
$attribute = $this->getRawOriginal('type'); |
76
|
|
|
|
77
|
|
|
return in_array($attribute ?? null, [1, 2]) |
78
|
|
|
? [ |
79
|
|
|
1 => 'success', |
80
|
|
|
2 => 'danger', |
81
|
|
|
][$attribute] |
82
|
|
|
: null; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function user() |
86
|
|
|
{ |
87
|
|
|
return $this->belongsTo(User::class); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths