Dashboard   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 58
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A scopeAllAvailable() 0 5 1
A user() 0 4 1
A widgets() 0 4 1
1
<?php
2
3
namespace App\Models;
4
5
use Illuminate\Database\Eloquent\Builder;
6
use Illuminate\Database\Eloquent\Model;
7
8
/**
9
 * App\Models\Dashboard
10
 *
11
 * @property integer $dashboard_id
12
 * @property integer $user_id
13
 * @property string $dashboard_name
14
 * @property integer $access
15
 * @property-read \App\Models\User $user
16
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\UsersWidgets[] $widgets
17
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Dashboard whereDashboardId($value)
18
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Dashboard whereUserId($value)
19
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Dashboard whereDashboardName($value)
20
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Dashboard whereAccess($value)
21
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Dashboard allAvailable($user)
22
 * @mixin \Eloquent
23
 */
24
class Dashboard extends Model
25
{
26
    /**
27
     * Indicates if the model should be timestamped.
28
     *
29
     * @var bool
30
     */
31
    public $timestamps = false;
32
    /**
33
     * The table associated with the model.
34
     *
35
     * @var string
36
     */
37
    protected $table = 'dashboards';
38
    /**
39
     * The primary key column name.
40
     *
41
     * @var string
42
     */
43
    protected $primaryKey = 'dashboard_id';
44
    /**
45
     * The attributes that are mass assignable.
46
     *
47
     * @var array
48
     */
49
    protected $fillable = ['user_id', 'dashboard_name', 'access'];
50
51
    // ---- Query scopes ----
52
53
    /**
54
     * @param Builder $query
55
     * @param $user
56
     * @return Builder|static
57
     */
58 4
    public function scopeAllAvailable(Builder $query, $user)
59
    {
60 4
        return $query->where('user_id', $user->user_id)
61 4
            ->orWhere('access', '>', 0);
62
    }
63
64
    // ---- Define Reletionships ----
65
66
    /**
67
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
68
     */
69
    public function user()
70
    {
71
        return $this->belongsTo('App\Models\User', 'user_id');
72
    }
73
74
    /**
75
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
76
     */
77 4
    public function widgets()
78
    {
79 4
        return $this->hasMany('App\Models\UsersWidgets', 'dashboard_id');
80
    }
81
}
82