Compare commits

...

1 Commits

Author SHA1 Message Date
snipe
7d0432cb1b Added useLocale accessor for mail alerts 2025-10-16 13:13:01 +01:00
3 changed files with 34 additions and 3 deletions

View File

@@ -57,7 +57,7 @@ class SendExpirationAlerts extends Command
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(
[
@@ -91,7 +91,7 @@ class SendExpirationAlerts extends Command
->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(
[

View File

@@ -60,7 +60,7 @@ class SendUpcomingAuditReport extends Command
$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(
[

View File

@@ -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;
@@ -120,6 +121,36 @@ class Setting extends Model
}
}
/**
* 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.
*