public function all() { $customer_ids = []; if (\KodeInfo\Utilities\Utils::isDepartmentAdmin(Auth::user()->id)) { $department_admin = DepartmentAdmins::where('user_id', Auth::user()->id)->first(); $department = Department::where('id', $department_admin->department_id)->first(); $customer_ids = CompanyCustomers::where("company_id", $department->company_id)->lists('customer_id'); } elseif (\KodeInfo\Utilities\Utils::isOperator(Auth::user()->id)) { $department_admin = OperatorsDepartment::where('user_id', Auth::user()->id)->first(); $department = Department::where('id', $department_admin->department_id)->first(); $customer_ids = CompanyCustomers::where("company_id", $department->company_id)->lists('customer_id'); } else { $customer_ids = CompanyCustomers::lists('customer_id'); } if (sizeof($customer_ids) > 0) { $this->data["customers"] = User::whereIn("id", $customer_ids)->orderBy('id', 'desc')->get(); } else { $this->data["customers"] = []; } foreach ($this->data["customers"] as $customer) { $company_id = CompanyCustomers::where("customer_id", $customer->id)->pluck('company_id'); $customer->company = Company::find($company_id); $customer->all_ticket_count = Tickets::where('customer_id', $customer->id)->count(); $customer->pending_ticket_count = Tickets::where('customer_id', $customer->id)->where('status', Tickets::TICKET_PENDING)->count(); $customer->resolved_ticket_count = Tickets::where('customer_id', $customer->id)->where('status', Tickets::TICKET_RESOLVED)->count(); } return View::make('customers.all', $this->data); }