$students = Student::query()
->correctStateScope()
->get();
$students->each(fn (Student $student) => $student->doSomething());
Setting cron for model related activities
Hi,
I have been reading material about how to set a cron in Laravel for scheduling tasks on some time frequency. However, almost all the examples are talking about some activity which is independent of any model or controller (does not engage any model or controller). For example: Sending emails to all users, or cleaning up database, etc. Both these commands are not using the active models in the application (sending email is triggering email app while database cleaning is using direct commands to database table to do something.
$totalUsers = \DB::table('users')
->whereRaw('Date(created_at) = CURDATE()')
->count();
Mail::to('[email protected]')->send(new SendMailable($totalUsers));
My requirement is different. I want to invoke a model (e.g. student), check his status at the start of the month (active, suspended, terminated), and post a stipend for him in another model (payment) table. This needs to be done for all the students which are active. This also involves logging user_id into different tables for doing the actions.
How do I do that?
Thanks, Saad
Please or to participate in this conversation.