filled('search')) { $baseQuery->whereAny( [ 'first_name', 'middle_name', 'last_name', ], 'LIKE', "%{$request->search}%" ); } if ($request->filled('email')) { $baseQuery->where('email', 'LIKE', "%{$$request->email}%"); } if ($query) { $query($baseQuery); } if ($paginate) { return $baseQuery->paginate($limit); } return $baseQuery->get(); } public function findById($id, callable $query = null) { $baseQuery = Employee::query(); if (is_callable($query)) { $query($baseQuery); } return $baseQuery->where('id', $id)->firstOrFail(); } public function delete($id) { $employee = $this->findById($id); $employee->delete(); return $employee; } public function create(array $data) { $employee = Employee::create($data); return $employee; } public function update($id, array $data) { $employee = $this->findById($id); $employee->update($data); return $employee; } public function pluck(callable $query = null) { $baseQuery = Employee::query(); if (is_callable($query)) { $query($baseQuery); } return $baseQuery->get()->mapWithKeys(function ($employee) { return [$employee->id => $employee->full_name]; }); } public function terminate($id){ $employee = $this->findById($id); $employee->update(["status" => "terminated"]); return $employee; } }