From d2e5563dbe563d0f833491cca1fe210b06120d8c Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 28 Mar 2019 21:16:41 +1100 Subject: [PATCH] Filter scope to company --- app/Filters/ClientFilters.php | 11 +++++------ app/Filters/QueryFilters.php | 2 ++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/Filters/ClientFilters.php b/app/Filters/ClientFilters.php index 7d29e78682..b1594a6276 100644 --- a/app/Filters/ClientFilters.php +++ b/app/Filters/ClientFilters.php @@ -167,12 +167,11 @@ class ClientFilters extends QueryFilters return $query; } - public function company() - { - $entity = strtolower(class_basename(Client::class)); + public function entityFilter() + { + + return $this->builder->whereCompanyId(auth()->user()->company()->id); - $this->builder->where($entity .'.company_id', '=', auth()->user()->company()->id); - - } + } } \ No newline at end of file diff --git a/app/Filters/QueryFilters.php b/app/Filters/QueryFilters.php index be5ae418f3..e07ca15793 100644 --- a/app/Filters/QueryFilters.php +++ b/app/Filters/QueryFilters.php @@ -61,6 +61,8 @@ abstract class QueryFilters { $this->builder = $builder; + $this->entityFilter(); + foreach ($this->filters() as $name => $value) { if (! method_exists($this, $name)) { continue;