ensurePortalAccess(); $contactId = $this->contactId(); $businessId = $this->businessId(); $ncrs = NcrReport::forBusiness($businessId) ->where(function ($q) use ($contactId) { $q->where('contact_id', $contactId) ->orWhere('source', 'customer'); }) ->latest('id') ->paginate(20); return view('qualitymanagement::portal.ncr.index', compact('ncrs')); } public function create() { $this->ensurePortalAccess(); return view('qualitymanagement::portal.ncr.create'); } public function store(Request $request, NcrWorkflowService $workflow, QmsIntegrationService $integration) { $this->ensurePortalAccess(); $validated = $request->validate([ 'title' => 'required|string|max:255', 'description' => 'nullable|string', 'severity' => 'required|in:minor,major,critical', ]); $workflow->createNcr($this->businessId(), array_merge($validated, [ 'source' => 'customer', 'contact_id' => $this->contactId(), 'status' => 'open', ]), $integration); return redirect()->action([self::class, 'index']) ->with('status', ['success' => 1, 'msg' => __('qualitymanagement::lang.ncr_created')]); } public function show($id) { $this->ensurePortalAccess(); $contactId = $this->contactId(); $ncr = NcrReport::forBusiness($this->businessId()) ->where(function ($q) use ($contactId) { $q->where('contact_id', $contactId) ->orWhere('source', 'customer'); }) ->with('capaActions') ->findOrFail($id); return view('qualitymanagement::portal.ncr.show', compact('ncr')); } }