CreateAvatar.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App\Jobs\AvatarPipeline;
  3. use App\Avatar;
  4. use App\Profile;
  5. use Illuminate\Bus\Queueable;
  6. use Illuminate\Contracts\Queue\ShouldQueue;
  7. use Illuminate\Foundation\Bus\Dispatchable;
  8. use Illuminate\Queue\InteractsWithQueue;
  9. use Illuminate\Queue\SerializesModels;
  10. class CreateAvatar implements ShouldQueue
  11. {
  12. use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
  13. protected $profile;
  14. /**
  15. * Delete the job if its models no longer exist.
  16. *
  17. * @var bool
  18. */
  19. public $deleteWhenMissingModels = true;
  20. /**
  21. * Create a new job instance.
  22. *
  23. * @return void
  24. */
  25. public function __construct(Profile $profile)
  26. {
  27. $this->profile = $profile;
  28. }
  29. /**
  30. * Execute the job.
  31. *
  32. * @return void
  33. */
  34. public function handle()
  35. {
  36. $profile = $this->profile;
  37. $path = 'public/avatars/default.jpg';
  38. $avatar = new Avatar();
  39. $avatar->profile_id = $profile->id;
  40. $avatar->media_path = $path;
  41. $avatar->change_count = 0;
  42. $avatar->last_processed_at = \Carbon\Carbon::now();
  43. $avatar->save();
  44. }
  45. }