faithgen /
laravel-sdk
| 1 | <?php |
||
| 2 | |||
| 3 | namespace FaithGen\SDK\Jobs\Users; |
||
| 4 | |||
| 5 | use FaithGen\SDK\Models\User; |
||
| 6 | use FaithGen\SDK\Traits\UploadsImages; |
||
| 7 | use Illuminate\Bus\Queueable; |
||
| 8 | use Illuminate\Contracts\Queue\ShouldQueue; |
||
| 9 | use Illuminate\Foundation\Bus\Dispatchable; |
||
| 10 | use Illuminate\Queue\InteractsWithQueue; |
||
| 11 | use Illuminate\Queue\SerializesModels; |
||
| 12 | use Intervention\Image\ImageManager; |
||
| 13 | |||
| 14 | class UploadImage implements ShouldQueue |
||
| 15 | { |
||
| 16 | use Dispatchable, |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 17 | InteractsWithQueue, |
||
| 18 | Queueable, |
||
| 19 | SerializesModels, |
||
| 20 | UploadsImages; |
||
| 21 | |||
| 22 | public bool $deleteWhenMissingModels = true; |
||
| 23 | /** |
||
| 24 | * @var User |
||
| 25 | */ |
||
| 26 | private User $user; |
||
| 27 | /** |
||
| 28 | * @var string |
||
| 29 | */ |
||
| 30 | private string $image; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Create a new job instance. |
||
| 34 | * |
||
| 35 | * @param User $user |
||
| 36 | * @param string $image |
||
| 37 | */ |
||
| 38 | public function __construct(User $user, string $image) |
||
| 39 | { |
||
| 40 | $this->user = $user; |
||
| 41 | $this->image = $image; |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Execute the job. |
||
| 46 | * |
||
| 47 | * @param ImageManager $imageManager |
||
| 48 | * |
||
| 49 | * @return void |
||
| 50 | */ |
||
| 51 | public function handle(ImageManager $imageManager) |
||
| 52 | { |
||
| 53 | if ($this->image) { |
||
| 54 | if ($this->user->image()->exists()) { |
||
| 55 | $fileName = $this->user->image->name; |
||
|
0 ignored issues
–
show
|
|||
| 56 | $this->uploadImages($this->user, [$this->image], $imageManager, $fileName); |
||
| 57 | } else { |
||
| 58 | $this->uploadImages($this->user, [$this->image], $imageManager); |
||
| 59 | } |
||
| 60 | } |
||
| 61 | } |
||
| 62 | } |
||
| 63 |