Controllers thay đổi
DepartmentController
Thay đổi chính
- company_id lấy từ auth — không nhận từ request (fix lỗi bảo mật)
- Company scope check — kiểm tra department có thuộc company của employee không
- Spatie permission middleware — route đã có middleware
permission:department.xxx
public function createDepartment(Request $request) {
$user = employee_account();
$companyId = $user->getCompanyAttribute()?->id;
$data = $request->validate([
'title' => 'string|required|max:255',
'status' => 'string|required|in:active,inactive',
'parent_id' => 'nullable|integer|exists:departments,id',
// KHÔNG còn company_id từ request
]);
$data['company_id'] = $companyId; // Lấy từ auth
if(isset($data['parent_id'])) {
$parentDept = $this->departmentService->findById($data['parent_id']);
// Kiểm tra parent thuộc cùng company
if ($parentDept->company_id != $companyId) {
return $this->error('Parent department does not belong to your company.', 403);
}
}
}
CompanyBranchController
Mới hoàn toàn (trước đây là class rỗng)
class CompanyBranchController extends APIController
{
protected ICompanyBranchService $branchService;
public function __construct(ICompanyBranchService $branchService) {
$this->branchService = $branchService;
}
public function getAll() { return $this->success($this->branchService->getAll()); }
public function getById($id) { /* tìm và trả về */ }
public function create(Request $request) { /* validate + tạo */ }
public function update($id, Request $request) { /* validate + cập nhật */ }
public function delete($id) { /* xoá */ }
}
CompanyController
Thay đổi
- Không thay đổi logic bên trong controller
- Route đã thêm
auth:employee + permission middleware
- Trước đây: routes public (không auth)
- Hiện tại: yêu cầu đăng nhập + permission cụ thể
EmployeeAccountController
Thay đổi
- Không thay đổi code controller
- Profile method vẫn load
'roles' — Spatie HasRoles cung cấp roles() relationship tương thích