@@ -55,11 +55,11 @@ public function store(UploadFileRequest $request, $accessoryId = null) : Redirec
5555
5656 }
5757
58- return redirect ()->route ('accessories.show ' , $ accessory ->id )->with ('error ' , trans ('general.no_files_uploaded ' ));
58+ return redirect ()->route ('accessories.show ' , $ accessory ->id )->withFragment ( ' files ' )-> with ('error ' , trans ('general.no_files_uploaded ' ));
5959 }
6060 // Prepare the error message
61- return redirect ()->route ('accessories.index ' )
62- -> with ( ' error ' , trans ( ' general.file_does_not_exist ' ));
61+ return redirect ()->route ('accessories.index ' )-> with ( ' error ' , trans ( ' admin/accessories/message.does_not_exist ' ));
62+
6363 }
6464
6565 /**
@@ -72,29 +72,27 @@ public function store(UploadFileRequest $request, $accessoryId = null) : Redirec
7272 */
7373 public function destroy ($ accessoryId = null , $ fileId = null ) : RedirectResponse
7474 {
75- $ accessory = Accessory::find ($ accessoryId );
76-
77- // the asset is valid
78- if (isset ($ accessory ->id )) {
75+ if ($ accessory = Accessory::find ($ accessoryId )) {
7976 $ this ->authorize ('update ' , $ accessory );
80- $ log = Actionlog::find ($ fileId );
8177
82- // Remove the file if one exists
83- if (Storage::exists ('accessories/ ' .$ log ->filename )) {
84- try {
85- Storage::delete ('accessories/ ' .$ log ->filename );
86- } catch (\Exception $ e ) {
87- Log::debug ($ e );
78+ if ($ log = Actionlog::find ($ fileId )) {
79+
80+ if (Storage::exists ('private_uploads/accessories/ ' .$ log ->filename )) {
81+ try {
82+ Storage::delete ('private_uploads/accessories/ ' . $ log ->filename );
83+ $ log ->delete ();
84+ return redirect ()->back ()->withFragment ('files ' )->with ('success ' , trans ('admin/hardware/message.deletefile.success ' ));
85+ } catch (\Exception $ e ) {
86+ Log::debug ($ e );
87+ return redirect ()->route ('accessories.index ' )->with ('error ' , trans ('general.file_does_not_exist ' ));
88+ }
8889 }
89- }
90-
91- $ log ->delete ();
9290
93- return redirect ()->back ()->withFragment ('files ' )->with ('success ' , trans ('admin/hardware/message.deletefile.success ' ));
91+ }
92+ return redirect ()->route ('accessories.show ' , ['accessory ' => $ accessory ])->withFragment ('files ' )->with ('error ' , trans ('general.log_record_not_found ' ));
9493 }
9594
96- // Redirect to the licence management page
97- return redirect ()->route ('accessories.index ' )->with ('error ' , trans ('general.file_does_not_exist ' ));
95+ return redirect ()->route ('accessories.index ' )->with ('error ' , trans ('admin/accessories/message.does_not_exist ' ));
9896 }
9997
10098 /**
@@ -124,10 +122,11 @@ public function show($accessoryId = null, $fileId = null) : View | RedirectRespo
124122 }
125123 }
126124
127- return redirect ()->route ('accessories.show ' , ['accessory ' => $ accessory ])->with ('error ' , trans ('general.log_record_not_found ' ));
125+ return redirect ()->route ('accessories.show ' , ['accessory ' => $ accessory ])->withFragment ( ' files ' )-> with ('error ' , trans ('general.log_record_not_found ' ));
128126
129127 }
130128
131- return redirect ()->route ('accessories.index ' )->with ('error ' , trans ('general.file_not_found ' ));
129+ return redirect ()->route ('accessories.index ' )->with ('error ' , trans ('admin/accessories/message.does_not_exist ' ));
130+
132131 }
133132}
0 commit comments