2
2
3
3
namespace App \Http \Controllers \Project ;
4
4
5
+ use App \Enums \StatusEnum ;
5
6
use App \Http \Controllers \Controller ;
6
7
use App \Models \Project ;
7
8
use App \Rules \FileUpload ;
@@ -20,16 +21,24 @@ class ScreenshotController extends Controller
20
21
*/
21
22
public function store (Request $ request , Project $ project ): JsonResponse
22
23
{
23
- $ this ->authorize ('update ' , $ project );
24
+ $ this ->authorize ('updateImages ' , $ project );
24
25
25
26
$ request ->validate ([
26
27
'screenshots_path ' => ['required ' , 'array ' , 'max:5 ' ],
27
28
'screenshots_path.* ' => ['bail ' , 'required ' , 'string ' , new FileUpload (['image/png ' , 'image/jpeg ' ])],
28
29
]);
29
30
30
- foreach ($ request ->input ('screenshots_path ' ) as $ screenshot ) {
31
- $ project ->addMediaFromDisk ($ screenshot )
32
- ->toMediaCollection ('screenshots ' );
31
+ if ($ project ->status === StatusEnum::Draft) {
32
+ foreach ($ request ->input ('screenshots_path ' ) as $ screenshot ) {
33
+ $ project ->addMediaFromDisk ($ screenshot )
34
+ ->toMediaCollection ('screenshots ' );
35
+ }
36
+ } else {
37
+ $ changeProposal = $ project ->latestChangeProposal ;
38
+ $ changeProposal ->update (['data ' => [
39
+ ...$ changeProposal ->data ,
40
+ 'screenshots_path ' => $ request ->input ('screenshots_path ' ),
41
+ ]]);
33
42
}
34
43
35
44
return new JsonResponse (['message ' => 'Screenshots has been saved successfully. ' ]);
@@ -40,7 +49,7 @@ public function store(Request $request, Project $project): JsonResponse
40
49
*/
41
50
public function destroy (Project $ project , int $ media ): JsonResponse
42
51
{
43
- $ this ->authorize ('update ' , $ project );
52
+ $ this ->authorize ('deleteImages ' , $ project );
44
53
45
54
$ project ->screenshots ()
46
55
->where ('id ' , $ media )
0 commit comments