2

I have three model classes: Userinfo, Winners, Participants

UserInfo id, user_code, created_at

Winners id, user_code, prize

Participants id, user_code, prize

  1. I want to select 5 user_code at random each day from UserInfo and save the into Winners. prize = winners, user_code will be the user_code from UserInfo

  2. I want to select other 3 user_code at random each day from UserInfo and save the into Winners. prize = participants, user_code will be the user_code from UserInfo. But this three users here will be different from the five users in Winners.

How do I write Laravel code for this? Thanks

Mofolumike
  • 53
  • 2
  • 3
  • 10
  • 1
    Possible duplicate of [Laravel - Eloquent or Fluent random row](https://stackoverflow.com/questions/13917558/laravel-eloquent-or-fluent-random-row) – Douwe de Haan Jun 27 '19 at 10:02

1 Answers1

2

You can make a backend job which will repeat every day and use Participants::inRandomOrder()->limit(5)->get() method of eloquent for random users. Check here about daily jobs:- https://laravel.com/docs/5.8/queues

Sahil Gupta
  • 578
  • 5
  • 16