Skip to content

Commit

Permalink
added user id scope
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Jan 29, 2021
1 parent 26451e0 commit 42af602
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/Models/Common/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,20 @@ public function scopeEnabled($query, $value = 1)
return $query->where('enabled', $value);
}

/**
* Scope to only include companies of a given user id.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int $user_id
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeUserId($query, $user_id)
{
return $query->whereHas('users', function ($query) use ($user_id) {
$query->where('user_id', $user_id);
});
}

/**
* Sort by company name
*
Expand Down
14 changes: 14 additions & 0 deletions app/Models/Common/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,20 @@ public function widgets()
return $this->hasMany('App\Models\Common\Widget')->orderBy('sort', 'asc');
}

/**
* Scope to only include dashboards of a given user id.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int $user_id
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeUserId($query, $user_id)
{
return $query->whereHas('users', function ($query) use ($user_id) {
$query->where('user_id', $user_id);
});
}

/**
* Create a new factory instance for the model.
*
Expand Down

0 comments on commit 42af602

Please sign in to comment.