@@ -26,11 +26,8 @@ class AssetFilesController extends Controller
2626 *@since [v1.0]
2727 * @author [A. Gianotto] [<[email protected] >] 2828 */
29- public function store (UploadFileRequest $ request , $ assetId = null ) : RedirectResponse
29+ public function store (UploadFileRequest $ request , Asset $ asset ) : RedirectResponse
3030 {
31- if (! $ asset = Asset::find ($ assetId )) {
32- return redirect ()->route ('hardware.index ' )->with ('error ' , trans ('admin/hardware/message.does_not_exist ' ));
33- }
3431
3532 $ this ->authorize ('update ' , $ asset );
3633
@@ -59,31 +56,28 @@ public function store(UploadFileRequest $request, $assetId = null) : RedirectRes
5956 * @param int $fileId
6057 * @since [v1.0]
6158 */
62- public function show ($ assetId = null , $ fileId = null ) : View | RedirectResponse | Response | StreamedResponse | BinaryFileResponse
59+ public function show (Asset $ asset , $ fileId = null ) : View | RedirectResponse | Response | StreamedResponse | BinaryFileResponse
6360 {
64- if ($ asset = Asset::find ($ assetId )) {
65-
66- $ this ->authorize ('view ' , $ asset );
6761
68- if ($ log = Actionlog::whereNotNull ('filename ' )->where ('item_id ' , $ asset ->id )->find ($ fileId )) {
69- $ file = 'private_uploads/assets/ ' .$ log ->filename ;
62+ $ this ->authorize ('view ' , $ asset );
7063
71- if ($ log ->action_type == 'audit ' ) {
72- $ file = 'private_uploads/audits/ ' .$ log ->filename ;
73- }
64+ if ($ log = Actionlog::whereNotNull ('filename ' )->where ('item_id ' , $ asset ->id )->find ($ fileId )) {
65+ $ file = 'private_uploads/assets/ ' .$ log ->filename ;
7466
75- try {
76- return StorageHelper::showOrDownloadFile ($ file , $ log ->filename );
77- } catch (\Exception $ e ) {
78- return redirect ()->route ('hardware.show ' , ['hardware ' => $ asset ])->with ('error ' , trans ('general.file_not_found ' ));
79- }
67+ if ($ log ->action_type == 'audit ' ) {
68+ $ file = 'private_uploads/audits/ ' .$ log ->filename ;
69+ }
8070
71+ try {
72+ return StorageHelper::showOrDownloadFile ($ file , $ log ->filename );
73+ } catch (\Exception $ e ) {
74+ return redirect ()->route ('hardware.show ' , ['hardware ' => $ asset ])->with ('error ' , trans ('general.file_not_found ' ));
8175 }
8276
83- return redirect ()->route ('hardware.show ' , ['hardware ' => $ asset ])->with ('error ' , trans ('general.log_record_not_found ' ));
8477 }
8578
86- return redirect ()->route ('hardware.index ' )->with ('error ' , trans ('admin/hardware/message.does_not_exist ' ));
79+ return redirect ()->route ('hardware.show ' , ['hardware ' => $ asset ])->with ('error ' , trans ('general.log_record_not_found ' ));
80+
8781
8882 }
8983
@@ -95,23 +89,20 @@ public function show($assetId = null, $fileId = null) : View | RedirectResponse
9589 * @param int $fileId
9690 * @since [v1.0]
9791 */
98- public function destroy ($ assetId = null , $ fileId = null ) : RedirectResponse
92+ public function destroy (Asset $ asset , $ fileId = null ) : RedirectResponse
9993 {
100- if ($ asset = Asset::find ($ assetId )) {
101- $ this ->authorize ('update ' , $ asset );
102- $ rel_path = 'private_uploads/assets ' ;
103-
104- if ($ log = Actionlog::find ($ fileId )) {
105- if (Storage::exists ($ rel_path .'/ ' .$ log ->filename )) {
106- Storage::delete ($ rel_path .'/ ' .$ log ->filename );
107- }
108- $ log ->delete ();
109- return redirect ()->back ()->withFragment ('files ' )->with ('success ' , trans ('admin/hardware/message.deletefile.success ' ));
110- }
94+ $ this ->authorize ('update ' , $ asset );
95+ $ rel_path = 'private_uploads/assets ' ;
11196
112- return redirect ()->route ('hardware.show ' , ['hardware ' => $ asset ])->with ('error ' , trans ('general.log_record_not_found ' ));
97+ if ($ log = Actionlog::find ($ fileId )) {
98+ if (Storage::exists ($ rel_path .'/ ' .$ log ->filename )) {
99+ Storage::delete ($ rel_path .'/ ' .$ log ->filename );
100+ }
101+ $ log ->delete ();
102+ return redirect ()->back ()->withFragment ('files ' )->with ('success ' , trans ('admin/hardware/message.deletefile.success ' ));
113103 }
114104
115- return redirect ()->route ('hardware.index ' )->with ('error ' , trans ('admin/hardware/message.does_not_exist ' ));
105+ return redirect ()->route ('hardware.show ' , [ ' hardware ' => $ asset ] )->with ('error ' , trans ('general.log_record_not_found ' ));
116106 }
107+
117108}
0 commit comments