1 | <?php |
||
13 | class UploadImage implements ShouldQueue |
||
14 | { |
||
15 | use Dispatchable, |
||
16 | InteractsWithQueue, |
||
17 | Queueable, |
||
18 | SerializesModels; |
||
19 | |||
20 | public bool $deleteWhenMissingModels = true; |
||
|
|||
21 | protected News $article; |
||
22 | |||
23 | protected $image; |
||
24 | |||
25 | /** |
||
26 | * Create a new job instance. |
||
27 | * |
||
28 | * @return void |
||
29 | */ |
||
30 | public function __construct(News $article, $image) |
||
31 | { |
||
32 | $this->article = $article; |
||
33 | $this->image = $image; |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * Execute the job. |
||
38 | * |
||
39 | * @param ImageManager $imageManager |
||
40 | * |
||
41 | * @return void |
||
42 | */ |
||
43 | public function handle(ImageManager $imageManager) |
||
44 | { |
||
45 | if ($this->image) { |
||
46 | $fileName = str_shuffle($this->article->id.time().time()).'.png'; |
||
47 | $ogSave = storage_path('app/public/news/original/').$fileName; |
||
48 | $imageManager->make($this->image)->save($ogSave); |
||
49 | $this->article->image()->updateOrcreate([ |
||
50 | 'imageable_id' => $this->article->id, |
||
51 | ], [ |
||
52 | 'name' => $fileName, |
||
57 |