Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/Console/Commands/SendExpirationAlerts.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function handle()

if ($assets->count() > 0) {

Mail::to($recipients)->send(new ExpiringAssetsMail($assets, $alert_interval));
Mail::to($recipients)->locale($settings->use_locale)->send(new ExpiringAssetsMail($assets, $alert_interval));

$this->table(
[
Expand Down Expand Up @@ -91,7 +91,7 @@ public function handle()
->orderBy('termination_date', 'ASC')
->get();
if ($licenses->count() > 0) {
Mail::to($recipients)->send(new ExpiringLicenseMail($licenses, $alert_interval));
Mail::to($recipients)->locale($settings->use_locale)->send(new ExpiringLicenseMail($licenses, $alert_interval));

$this->table(
[
Expand Down
2 changes: 1 addition & 1 deletion app/Console/Commands/SendUpcomingAuditReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function handle()


$this->info('Sending Admin SendUpcomingAuditNotification to: ' . $settings->alert_email);
Mail::to($recipients)->send(new SendUpcomingAuditMail($assets, $settings->audit_warning_days));
Mail::to($recipients)->locale($settings->use_locale)->send(new SendUpcomingAuditMail($assets, $settings->audit_warning_days));

$this->table(
[
Expand Down
31 changes: 31 additions & 0 deletions app/Models/Setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
Expand Down Expand Up @@ -120,6 +121,36 @@ public static function setupCompleted(): bool
}
}

/**
* Get the locale to use in some places in the app where we don't
* have access to the user context (i.e. email notifications where the alert address
* might not be an actual user object or it's being run via cli.)
*
* @return \Illuminate\Database\Eloquent\Casts\Attribute
*/
protected function useLocale(): Attribute
{

return Attribute:: make(
get: function(mixed $value, array $attributes) {

// Use current user's language
if ((request()->user()) && (request()->user()->locale)) {
return request()->user()->locale;

// Fall back to app settings
} elseif ($attributes['locale'] != '') {
return $attributes['locale'];
}

// Fall back to env
return config('app.locale');

}
);

}

/**
* Get the current Laravel version.
*
Expand Down
Loading