3
3
namespace App \Jobs ;
4
4
5
5
use Illuminate \Bus \Queueable ;
6
+ use Illuminate \Contracts \Filesystem \Filesystem ;
6
7
use Illuminate \Contracts \Queue \ShouldBeUnique ;
7
8
use Illuminate \Contracts \Queue \ShouldQueue ;
8
9
use Illuminate \Foundation \Bus \Dispatchable ;
@@ -24,34 +25,45 @@ class ImageUploadAndResizingJob implements ShouldQueue
24
25
'640x480 ' => [640 , 480 ],
25
26
];
26
27
28
+ private ?Filesystem $ storage ;
29
+
27
30
/**
28
31
* Create a new job instance.
29
32
*
30
33
* @return void
31
34
*/
32
- public function __construct (string $ mimeType , string $ imageContent )
35
+ public function __construct (string $ mimeType , string $ imageContent, ? Filesystem $ storage = null )
33
36
{
34
37
$ this ->mimeType = $ mimeType ;
35
38
$ this ->imageContent = $ imageContent ;
39
+ $ this ->storage = $ storage ;
40
+ }
41
+
42
+ public function storage ()
43
+ {
44
+ if (! $ this ->storage )
45
+ $ this ->storage = Storage::disk ('public ' );
46
+
47
+ return $ this ->storage ;
36
48
}
37
49
38
50
/**
39
51
* Execute the job.
40
52
*
41
- * @return array
53
+ * @return array|bool
42
54
*/
43
55
public function handle ()
44
56
{
45
- $ storage = Storage::disk ('public ' );
46
-
47
57
$ path = 'fake-image-name.jpg ' ;
48
58
49
- $ storage ->put ($ path , base64_decode ($ this ->imageContent ));
59
+ if (! $ this ->storage ()->put ($ path , base64_decode ($ this ->imageContent ))) {
60
+ return false ;
61
+ }
50
62
51
63
$ paths = [];
52
64
53
65
foreach ($ this ->resolutions as $ key => $ resolution ) {
54
- $ image = Image::make ($ absolutePath = $ storage ->path ($ path ))
66
+ $ image = Image::make ($ absolutePath = $ this -> storage () ->path ($ path ))
55
67
->resize ($ resolution [0 ], $ resolution [1 ])
56
68
->save ($ this ->absolutePathWithResolutionKey ($ absolutePath , $ key ));
57
69
0 commit comments