@@ -144,10 +144,9 @@ public function store(CustomFieldRequest $request) : RedirectResponse
144144 */
145145 public function deleteFieldFromFieldset ($ field_id , $ fieldset_id ) : RedirectResponse
146146 {
147+ $ this ->authorize ('update ' , CustomField::class);
147148 $ field = CustomField::find ($ field_id );
148149
149- $ this ->authorize ('update ' , $ field );
150-
151150 // Check that the field exists - this is mostly related to the demo, where we
152151 // rewrite the data every x minutes, so it's possible someone might be disassociating
153152 // a field from a fieldset just as we're wiping the database
@@ -157,11 +156,12 @@ public function deleteFieldFromFieldset($field_id, $fieldset_id) : RedirectRespo
157156 return redirect ()->route ('fieldsets.show ' , ['fieldset ' => $ fieldset_id ])
158157 ->with ('success ' , trans ('admin/custom_fields/message.field.delete.success ' ));
159158 } else {
160- return redirect ()->back ()->withErrors (['message ' => "Field is in use and cannot be deleted. " ]);
159+ return redirect ()->back ()->with ('error ' , trans ('admin/custom_fields/message.field.delete.error ' ))
160+ ->withInput ();
161161 }
162162 }
163163
164- return redirect ()->back ()->withErrors ([ ' message ' => " Error deleting field from fieldset " ] );
164+ return redirect ()->back ()->with ( ' error ' , trans ( ' admin/custom_fields/message. field.delete.error ' ) );
165165
166166
167167 }
@@ -172,20 +172,16 @@ public function deleteFieldFromFieldset($field_id, $fieldset_id) : RedirectRespo
172172 * @author [Brady Wetherington] [<[email protected] >] 173173 * @since [v1.8]
174174 */
175- public function destroy ($ field_id ) : RedirectResponse
175+ public function destroy (CustomField $ field ) : RedirectResponse
176176 {
177- if ($ field = CustomField::find ($ field_id )) {
178- $ this ->authorize ('delete ' , $ field );
177+ $ this ->authorize ('delete ' , CustomField::class);
179178
180- if (($ field ->fieldset ) && ($ field ->fieldset ->count () > 0 )) {
181- return redirect ()->back ()->withErrors (['message ' => 'Field is in-use ' ]);
182- }
183- $ field ->delete ();
184- return redirect ()->route ("fields.index " )
185- ->with ("success " , trans ('admin/custom_fields/message.field.delete.success ' ));
179+ if (($ field ->fieldset ) && ($ field ->fieldset ->count () > 0 )) {
180+ return redirect ()->back ()->with ('error ' , trans ('admin/custom_fields/message.field.delete.in_use ' ));
186181 }
187-
188- return redirect ()->back ()->withErrors (['message ' => 'Field does not exist ' ]);
182+ $ field ->delete ();
183+ return redirect ()->route ("fields.index " )
184+ ->with ("success " , trans ('admin/custom_fields/message.field.delete.success ' ));
189185 }
190186
191187
@@ -198,7 +194,7 @@ public function destroy($field_id) : RedirectResponse
198194 */
199195 public function edit (Request $ request , CustomField $ field ) : View | RedirectResponse
200196 {
201- $ this ->authorize ('update ' , $ field );
197+ $ this ->authorize ('update ' , CustomField::class );
202198 $ fieldsets = CustomFieldset::get ();
203199 $ customFormat = '' ;
204200 if ((stripos ($ field ->format , 'regex ' ) === 0 ) && ($ field ->format !== CustomField::PREDEFINED_FORMATS ['MAC ' ])) {
@@ -228,7 +224,7 @@ public function edit(Request $request, CustomField $field) : View | RedirectResp
228224 */
229225 public function update (CustomFieldRequest $ request , CustomField $ field ) : RedirectResponse
230226 {
231- $ this ->authorize ('update ' , $ field );
227+ $ this ->authorize ('update ' , CustomField::class );
232228 $ show_in_email = $ request ->get ("show_in_email " , 0 );
233229 $ display_in_user_view = $ request ->get ("display_in_user_view " , 0 );
234230
@@ -265,7 +261,6 @@ public function update(CustomFieldRequest $request, CustomField $field) : Redire
265261
266262 if ($ field ->save ()) {
267263
268-
269264 // Sync fields with fieldsets
270265 $ fieldset_array = $ request ->input ('associate_fieldsets ' );
271266 if ($ request ->has ('associate_fieldsets ' ) && (is_array ($ fieldset_array ))) {
0 commit comments