SeedFollows.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Follower;
  4. use App\Jobs\FollowPipeline\FollowPipeline;
  5. use App\Profile;
  6. use Illuminate\Console\Command;
  7. class SeedFollows extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'seed:follows';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = 'Seed follows for testing';
  21. /**
  22. * Create a new command instance.
  23. *
  24. * @return void
  25. */
  26. public function __construct()
  27. {
  28. parent::__construct();
  29. }
  30. /**
  31. * Execute the console command.
  32. *
  33. * @return mixed
  34. */
  35. public function handle()
  36. {
  37. $limit = 100;
  38. for ($i = 0; $i < $limit; $i++) {
  39. try {
  40. $actor = Profile::whereDomain(false)->inRandomOrder()->firstOrFail();
  41. $target = Profile::whereDomain(false)->inRandomOrder()->firstOrFail();
  42. if($actor->id == $target->id) {
  43. continue;
  44. }
  45. $follow = Follower::firstOrCreate([
  46. 'profile_id' => $actor->id,
  47. 'following_id' => $target->id
  48. ]);
  49. if($follow->wasRecentlyCreated == true) {
  50. FollowPipeline::dispatch($follow);
  51. }
  52. } catch (Exception $e) {
  53. continue;
  54. }
  55. }
  56. }
  57. }