0

I am using Laravel 8 for an HRMS application. It has multiple companies, and each user belongs to a company. Initially, I was using it for a single company. But now, it's for multiple companies with a singular database. The user table has company_id.

Models

class Company extends Model
{
    protected $table = 'companies';

    protected $fillable = [
        'id',
        'organization_code',
        'organization_name'
    ];
}

class User extends Authenticatable
{
    use Notifiable;

    protected $fillable = [
        'name',
        'first_name',
        'last_name',
        'company_id',
        'email',
    ];
}

config/mail.php

 return [
    'driver' => env('MAIL_DRIVER', 'smtp'),
    'host' => env('MAIL_HOST', 'smtp.office365.com'),
    'port' => env('MAIL_PORT', 587),

    'from' => [
        'address' => env('MAIL_FROM_ADDRESS', 'admin@company1.com'),
        'name' => env('MAIL_FROM_NAME', 'COMPANY1'),
    ],

    'encryption' => env('MAIL_ENCRYPTION', 'tls'),
    'username' => env('MAIL_USERNAME','mailer@company1.com'),
    'password' => env('MAIL_PASSWORD','company1'),    
    'sendmail' => '/usr/sbin/sendmail -bs',

    'log_channel' => env('MAIL_LOG_CHANNEL'),
];

The above mail credential is for the company1, but now I have company1, comany2, company3, ... and so on. Each company will have its mail credential.

$details = [
    'subject' => '',
    'greeting' => '',
    'body' => ' ',
    'line1' => '',
    'thanks' => 'Thank you!',
    'user_email' => $userEmail,
    'actionText' => '',
];

Notification::route('mail', $details['user_email'])
    ->notify(new \App\Notifications\UserApprove($details))

How do I send the notification based on the mail credential of the company of the logged-in user?

Karl Hill
  • 12,937
  • 5
  • 58
  • 95
user11352561
  • 2,277
  • 12
  • 51
  • 102

0 Answers0