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