widget refactoring
This commit is contained in:
@ -28,9 +28,7 @@ class Dashboard extends Controller
|
||||
session(['dashboard_id' => $dashboard_id]);
|
||||
}
|
||||
|
||||
$user_id = user()->id;
|
||||
|
||||
$dashboards = Model::where('user_id', $user_id)->enabled()->get();
|
||||
$dashboards = Model::where('user_id', user()->id)->enabled()->get();
|
||||
|
||||
if (!$dashboard_id) {
|
||||
$dashboard_id = $dashboards->first()->id;
|
||||
|
@ -25,16 +25,16 @@ class Dashboard extends Model
|
||||
*/
|
||||
public $sortable = ['name', 'enabled'];
|
||||
|
||||
public function widgets()
|
||||
{
|
||||
return $this->hasMany('App\Models\Common\Widget')->orderBy('sort', 'asc');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Auth\User', 'user_id', 'id');
|
||||
}
|
||||
|
||||
public function widgets()
|
||||
{
|
||||
return $this->hasMany('App\Models\Common\Widget')->orderBy('sort', 'asc');
|
||||
}
|
||||
|
||||
public function scopeOfUser($query, $user_id)
|
||||
{
|
||||
return $query->where('user_id', $user_id);
|
||||
|
@ -31,4 +31,9 @@ class Widget extends Model
|
||||
{
|
||||
return $this->belongsTo('App\Models\Common\Dashboard');
|
||||
}
|
||||
|
||||
public function user()
|
||||
{
|
||||
return $this->hasOneThrough('App\Models\Auth\User', 'App\Models\Common\Dashboard');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user