Spot   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 28
c 2
b 0
f 0
dl 0
loc 56
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getImageAttribute() 0 3 2
A scopeMostRecent() 0 7 1
A scopeFeatured() 0 7 1
A country() 0 3 1
A getRouteKeyName() 0 3 1
1
<?php
2
3
namespace App;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class Spot extends Model
8
{
9
    protected $fillable = [
10
        'name',
11
        'slug',
12
        'address',
13
        'email',
14
        'phone_number',
15
        'city',
16
        'country_id',
17
        'image',
18
        'website',
19
        'latitude',
20
        'longitude',
21
        'is_approved',
22
        'is_featured',
23
    ];
24
25
    public function getRouteKeyName()
26
    {
27
        return 'slug';
28
    }
29
30
    public function country()
31
    {
32
        return $this->belongsTo(Country::class);
33
    }
34
35
    public function getImageAttribute($imagePath)
36
    {
37
        return ($imagePath ? asset("storage/$imagePath") : null);
38
    }
39
40
    /**
41
     * Returns the 3 most recent Spots that have an image
42
     * and are approved
43
     *
44
     * @param $query
45
     * @param int $take
46
     */
47
    public function scopeMostRecent($query, $take = 3)
48
    {
49
        $query->with('country')
50
            ->where('is_approved', true)
51
            ->where('image', '!=', null)
52
            ->orderBy('created_at', 'desc')
53
            ->take($take);
54
    }
55
56
    public function scopeFeatured($query, $take = 3)
57
    {
58
        $query->with('country')
59
            ->where('is_approved', true)
60
            ->orderBy('is_featured', 'desc')
61
            ->orderBy('created_at', 'desc')
62
            ->take($take);
63
    }
64
}
65