@@ -55,7 +55,28 @@ public function mount(int|string $record): void
5555
5656 protected function authorizeAccess (): void
5757 {
58- abort_unless (CaseResource::canEdit ($ this ->beneficiary ?? $ this ->getRecord ()), 403 );
58+ abort_unless (CaseResource::canEdit ($ this ->resolveCaseBeneficiary ()), 403 );
59+ }
60+
61+ protected function resolveCaseBeneficiary (): Beneficiary
62+ {
63+ if ($ this ->beneficiary instanceof Beneficiary) {
64+ return $ this ->beneficiary ;
65+ }
66+
67+ $ monthlyPlan = $ this ->getRecord ();
68+ if (! $ monthlyPlan instanceof MonthlyPlan) {
69+ abort (404 );
70+ }
71+
72+ $ monthlyPlan ->loadMissing (['beneficiary ' , 'interventionPlan.beneficiary ' ]);
73+
74+ $ beneficiary = $ monthlyPlan ->beneficiary ?? $ monthlyPlan ->interventionPlan ?->beneficiary;
75+ if (! $ beneficiary instanceof Beneficiary) {
76+ abort (404 );
77+ }
78+
79+ return $ beneficiary ;
5980 }
6081
6182 public function getTitle (): string |Htmlable
@@ -65,11 +86,11 @@ public function getTitle(): string|Htmlable
6586
6687 public function getBreadcrumbs (): array
6788 {
68- $ record = $ this ->beneficiary ?? $ this -> getRecord ();
89+ $ record = $ this ->resolveCaseBeneficiary ();
6990
7091 return [
7192 CaseResource::getUrl ('index ' ) => __ ('case.view.breadcrumb_all ' ),
72- CaseResource::getUrl ('view ' , ['record ' => $ record ]) => $ record instanceof Beneficiary ? $ record ->getBreadcrumb () : '' ,
93+ CaseResource::getUrl ('view ' , ['record ' => $ record ]) => $ record ->getBreadcrumb (),
7394 CaseResource::getUrl ('view_intervention_plan ' , ['record ' => $ record ]) => __ ('intervention_plan.headings.view_page ' ),
7495 CaseResource::getUrl ('view_monthly_plan ' , ['record ' => $ record , 'monthlyPlan ' => $ this ->getRecord ()]) => __ ('intervention_plan.headings.monthly_plan ' ),
7596 '' => __ ('intervention_plan.headings.edit_monthly_plan_title ' ),
@@ -81,7 +102,7 @@ protected function getHeaderActions(): array
81102 return [
82103 BackAction::make ()
83104 ->url (CaseResource::getUrl ('view_monthly_plan ' , [
84- 'record ' => $ this ->beneficiary ,
105+ 'record ' => $ this ->resolveCaseBeneficiary () ,
85106 'monthlyPlan ' => $ this ->getRecord (),
86107 'tab ' => '- ' .str (\Illuminate \Support \Str::slug (__ ('intervention_plan.headings.monthly_plan_details ' )))->append ('-tab ' )->toString (),
87108 ])),
@@ -91,7 +112,7 @@ protected function getHeaderActions(): array
91112 protected function getRedirectUrl (): ?string
92113 {
93114 return CaseResource::getUrl ('view_monthly_plan ' , [
94- 'record ' => $ this ->beneficiary ,
115+ 'record ' => $ this ->resolveCaseBeneficiary () ,
95116 'monthlyPlan ' => $ this ->getRecord (),
96117 'tab ' => '- ' .str (\Illuminate \Support \Str::slug (__ ('intervention_plan.headings.monthly_plan_details ' )))->append ('-tab ' )->toString (),
97118 ]);
@@ -143,13 +164,13 @@ public function form(Schema $schema): Schema
143164 ->label (__ ('intervention_plan.labels.monthly_plan_end_date ' ))
144165 ->required (),
145166 Select::make ('case_manager_user_id ' )
146- ->label (__ ('intervention_plan.headings .case_manager ' ))
167+ ->label (__ ('intervention_plan.labels .case_manager ' ))
147168 ->options (User::getTenantOrganizationUsers ()->all ())
148169 ->placeholder (__ ('intervention_plan.placeholders.specialist ' )),
149170 Select::make ('specialists ' )
150- ->label (__ ('intervention_plan.labels.specialists ' ))
171+ ->label (__ ('intervention_plan.labels.case_team ' ))
151172 ->multiple ()
152- ->options (fn (): Collection => $ this ->beneficiary ? ->specialistsTeam()->with ('user ' , 'roleForDisplay ' )->get ()->pluck ('name_role ' , 'id ' ) ?? collect ( ))
173+ ->options (fn (): Collection => $ this ->resolveCaseBeneficiary () ->specialistsTeam ()->with ('user ' , 'roleForDisplay ' )->get ()->pluck ('name_role ' , 'id ' ))
153174 ->placeholder (__ ('intervention_plan.placeholders.specialists ' )),
154175 ]),
155176 ]);
0 commit comments