Completed
Push — main ( 7e4d39...6c6f0a )
by PRATIK
18s queued 15s
created

Service::getIconImageAttribute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Adminetic\Website\Models\Admin;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Support\Facades\Cache;
7
use Spatie\Activitylog\LogOptions;
0 ignored issues
show
Bug introduced by
The type Spatie\Activitylog\LogOptions 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...
8
use Spatie\Activitylog\Traits\LogsActivity;
0 ignored issues
show
Bug introduced by
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
use Spatie\MediaLibrary\HasMedia;
0 ignored issues
show
Bug introduced by
The type Spatie\MediaLibrary\HasMedia 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...
10
use Spatie\MediaLibrary\InteractsWithMedia;
0 ignored issues
show
Bug introduced by
The type Spatie\MediaLibrary\InteractsWithMedia 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...
11
use Spatie\SchemaOrg\Schema;
12
13
class Service extends Model implements HasMedia
14
{
15
    use LogsActivity, InteractsWithMedia;
16
17
    protected $guarded = [];
18
19
    // Forget cache on updating or saving and deleting
20
    public static function boot()
21
    {
22
        parent::boot();
23
24
        static::saving(function () {
25
            self::cacheKey();
26
        });
27
28
        static::deleting(function () {
29
            self::cacheKey();
30
        });
31
    }
32
33
    // Cache Keys
34
    private static function cacheKey()
35
    {
36
        Cache::has('services') ? Cache::forget('services') : '';
37
    }
38
39
    // Logs
40
    protected static $logName = 'service';
41
42
    public function getActivitylogOptions(): LogOptions
43
    {
44
        return LogOptions::defaults();
45
    }
46
47
    protected $casts = [
48
        'data' => 'array',
49
    ];
50
51
    public function __construct(array $attributes = [])
52
    {
53
        $this->table = config('website.table_prefix', 'website').'_services';
54
55
        parent::__construct($attributes);
56
    }
57
58
    // Relationships
59
    public function category()
60
    {
61
        return $this->belongsTo(Category::class);
62
    }
63
64
    public function inquiries()
65
    {
66
        return $this->hasMany(Inquiry::class);
67
    }
68
69
    // Scopes
70
    public function scopePosition($qry)
71
    {
72
        return $qry->orderBy('position');
73
    }
74
75
    public function scopeActive($qry)
76
    {
77
        return $qry->where('active', 1);
78
    }
79
80
    public function scopeFeatured($qry)
81
    {
82
        return $qry->where('featured', 1);
83
    }
84
85
    public function searchSchema()
86
    {
87
        $schema = Schema::service()
88
            ->name($this->meta_name ?? $this->name)
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on Adminetic\Website\Models\Admin\Service. Did you maybe forget to declare it?
Loading history...
Bug Best Practice introduced by
The property meta_name does not exist on Adminetic\Website\Models\Admin\Service. Did you maybe forget to declare it?
Loading history...
89
            ->description($this->meta_description ?? $this->excerpt)
0 ignored issues
show
Bug Best Practice introduced by
The property meta_description does not exist on Adminetic\Website\Models\Admin\Service. Did you maybe forget to declare it?
Loading history...
Bug Best Practice introduced by
The property excerpt does not exist on Adminetic\Website\Models\Admin\Service. Did you maybe forget to declare it?
Loading history...
90
            ->url(route('website.service', ['service' => $this->slug]))
0 ignored issues
show
Bug Best Practice introduced by
The property slug does not exist on Adminetic\Website\Models\Admin\Service. Did you maybe forget to declare it?
Loading history...
91
            ->keywords($this->meta_keywords);
0 ignored issues
show
Bug Best Practice introduced by
The property meta_keywords does not exist on Adminetic\Website\Models\Admin\Service. Did you maybe forget to declare it?
Loading history...
92
93
        return $schema->toScript();
94
    }
95
96
        // Accessors
97
        public function getImageAttribute()
98
        {
99
        return ! is_null($this->getFirstMedia('image')) ? $this->getFirstMediaUrl('image') : asset('adminetic/static/blog.gif');
100
        }
101
102
        // Accessors
103
        public function getIconImageAttribute()
104
        {
105
            return ! is_null($this->getFirstMedia('icon_image')) ? $this->getFirstMediaUrl('icon_image') : asset('adminetic/static/blog.gif');
106
        }
107
108
        
109
    
110
}
111