weiman99
1 month ago
131
3
Laravel

Get data from other table

Posted 1 month ago by weiman99

First of all, my database has two tables which is "licenses" and "users". I have this coding which is for me to track the expiry date of the user in "licenses" table and need to send an email to that user. But the email data of the user is in the "users" table, my questions is how i get the email data from "users" to "licenses"

$key = array_rand($words);
$value = $words[$key];
$users = License::whereDate('expiry_date',DB::raw('CURDATE()'))->get();

        foreach ($users as $user) {

            Mail::raw("{$key} -> {$value}", function ($mail) use ($user) {
                $mail->from('[email protected]');
                $mail->to($user->email)
                    ->subject('Licenses expired');
            });
        }
         
        $this->info('Email sent to users who license is expired');

Please sign in or create an account to participate in this conversation.