| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace App\Models; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Illuminate\Database\Eloquent\Model; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * App\Models\UsersWidgets | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @property integer $user_widget_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @property integer $user_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @property integer $widget_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @property boolean $col | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @property boolean $row | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * @property boolean $size_x | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * @property boolean $size_y | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * @property string $title | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * @property boolean $refresh | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * @property string $settings | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * @property integer $dashboard_id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * @method static \Illuminate\Database\Query\Builder|\App\Models\UsersWidgets whereUserWidgetId($value) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * @method static \Illuminate\Database\Query\Builder|\App\Models\UsersWidgets whereUserId($value) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * @method static \Illuminate\Database\Query\Builder|\App\Models\UsersWidgets whereWidgetId($value) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  * @method static \Illuminate\Database\Query\Builder|\App\Models\UsersWidgets whereCol($value) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  * @method static \Illuminate\Database\Query\Builder|\App\Models\UsersWidgets whereRow($value) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  * @method static \Illuminate\Database\Query\Builder|\App\Models\UsersWidgets whereSizeX($value) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  * @method static \Illuminate\Database\Query\Builder|\App\Models\UsersWidgets whereSizeY($value) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  * @method static \Illuminate\Database\Query\Builder|\App\Models\UsersWidgets whereTitle($value) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  * @method static \Illuminate\Database\Query\Builder|\App\Models\UsersWidgets whereRefresh($value) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  * @method static \Illuminate\Database\Query\Builder|\App\Models\UsersWidgets whereSettings($value) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  * @method static \Illuminate\Database\Query\Builder|\App\Models\UsersWidgets whereDashboardId($value) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  * @method static \Illuminate\Database\Query\Builder|\App\Models\Notification GetSettings($request) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  * @mixin \Eloquent | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  * @property-read \App\Models\User $user | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  * @property-read \App\Models\Widgets $widget | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  * @property-read \App\Models\Dashboard $dashboard | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | class UsersWidgets extends Model | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * Indicates if the model should be timestamped. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * @var bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     public $timestamps = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      * The table associated with the model. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     protected $table = 'users_widgets'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      * The primary key column name. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     protected $primaryKey = 'user_widget_id'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      * The attributes that are mass assignable. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     protected $fillable = ['user_id', 'widget_id', 'col', 'row', 'size_x', 'size_y', 'title', 'refresh', 'settings', 'dashboard_id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     // ---- Define Relationships ---- | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     public function user() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         return $this->belongsTo('App\Models\User', 'user_id'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |      * @return \Illuminate\Database\Eloquent\Relations\HasOne | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 77 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |     public function widget() | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |         return $this->hasOne('App\Models\Widgets', 'widget_id'); | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     public function dashboard() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         return $this->belongsTo('App\Models\Dashboard', 'dashboard_id'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     // ---- Query scopes ---- | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |     public function scopeGetSettings($query, $request) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         return $query->where([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |             ['user_widget_id', '=', $request->id], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |             ['user_id', '=', $request->user()->user_id] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         ])->select('settings'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 101 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 102 |  |  |  |