mirror of
https://github.com/anna-sara/vbytes_lan.git
synced 2026-03-16 16:25:41 +01:00
Added code to send sms when mail is sent
This commit is contained in:
parent
fcd7149161
commit
9cbd9904a2
4 changed files with 93 additions and 2 deletions
|
|
@ -15,6 +15,7 @@ use Filament\Actions\Action;
|
||||||
use Filament\Forms\Components\Select;
|
use Filament\Forms\Components\Select;
|
||||||
use Illuminate\Support\Facades\Mail;
|
use Illuminate\Support\Facades\Mail;
|
||||||
use App\Mail\LanMail;
|
use App\Mail\LanMail;
|
||||||
|
use App\Mail\SmsMail;
|
||||||
use Filament\Support\Icons\Heroicon;
|
use Filament\Support\Icons\Heroicon;
|
||||||
use App\Filament\Exports\ParticipantExporter;
|
use App\Filament\Exports\ParticipantExporter;
|
||||||
use Filament\Actions\ExportAction;
|
use Filament\Actions\ExportAction;
|
||||||
|
|
@ -146,6 +147,9 @@ class ParticipantsTable
|
||||||
Mail::to($record->guardian_email)
|
Mail::to($record->guardian_email)
|
||||||
->send(new LanMail($mailContent, $record));
|
->send(new LanMail($mailContent, $record));
|
||||||
Participant::where('id', $record->id)->update(['emailed' => true]);
|
Participant::where('id', $record->id)->update(['emailed' => true]);
|
||||||
|
Mail::to(config('app.smsUrl'))
|
||||||
|
->send(new SmsMail($record));
|
||||||
|
|
||||||
})
|
})
|
||||||
->hidden(fn($record) => $record->emailed),
|
->hidden(fn($record) => $record->emailed),
|
||||||
Action::make('sendRemindEmail')
|
Action::make('sendRemindEmail')
|
||||||
|
|
@ -162,8 +166,7 @@ class ParticipantsTable
|
||||||
->queue(new LanMail($mailContent, $record));
|
->queue(new LanMail($mailContent, $record));
|
||||||
Participant::where('id', $record->id)->update(['emailed' => true]);
|
Participant::where('id', $record->id)->update(['emailed' => true]);
|
||||||
})
|
})
|
||||||
->hidden(fn($record) => !$record->emailed)
|
->hidden(fn($record) => !$record->emailed),
|
||||||
|
|
||||||
])
|
])
|
||||||
->toolbarActions([
|
->toolbarActions([
|
||||||
BulkActionGroup::make([
|
BulkActionGroup::make([
|
||||||
|
|
|
||||||
86
app/Mail/SmsMail.php
Normal file
86
app/Mail/SmsMail.php
Normal file
|
|
@ -0,0 +1,86 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Mail;
|
||||||
|
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Mail\Mailable;
|
||||||
|
use Illuminate\Mail\Mailables\Content;
|
||||||
|
use Illuminate\Mail\Mailables\Envelope;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
class SmsMail extends Mailable
|
||||||
|
{
|
||||||
|
use Queueable, SerializesModels;
|
||||||
|
|
||||||
|
public $phone;
|
||||||
|
public $name;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new message instance.
|
||||||
|
*/
|
||||||
|
public function __construct($participant)
|
||||||
|
{
|
||||||
|
|
||||||
|
function formatToSwedenPrefix($phoneNumber) {
|
||||||
|
// 1. Remove everything that is NOT a digit
|
||||||
|
$cleaned = preg_replace('/[^0-9]/', '', $phoneNumber);
|
||||||
|
|
||||||
|
info($cleaned);
|
||||||
|
|
||||||
|
// 2. Check existing prefixes and format accordingly
|
||||||
|
if (str_starts_with($cleaned, '0046')) {
|
||||||
|
// Already correct
|
||||||
|
return $cleaned;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (str_starts_with($cleaned, '46')) {
|
||||||
|
// Starts with 46 (e.g. was +46), add 00
|
||||||
|
return '00' . $cleaned;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (str_starts_with($cleaned, '0')) {
|
||||||
|
// Starts with 0 (local format), remove 0 and add 0046
|
||||||
|
return '0046' . substr($cleaned, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback: Assume it's a number missing the prefix entirely
|
||||||
|
return '0046' . $cleaned;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->name = $participant->first_name;
|
||||||
|
$this->phone = formatToSwedenPrefix($participant->guardian_phone);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the message envelope.
|
||||||
|
*/
|
||||||
|
public function envelope(): Envelope
|
||||||
|
{
|
||||||
|
return new Envelope(
|
||||||
|
subject: $this->phone,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the message content definition.
|
||||||
|
*/
|
||||||
|
public function content(): Content
|
||||||
|
{
|
||||||
|
return new Content(
|
||||||
|
view: 'mail.sms',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the attachments for the message.
|
||||||
|
*
|
||||||
|
* @return array<int, \Illuminate\Mail\Mailables\Attachment>
|
||||||
|
*/
|
||||||
|
public function attachments(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -126,5 +126,6 @@ return [
|
||||||
],
|
],
|
||||||
|
|
||||||
'lanplace_amount' => env('LAN_PLACE_AMOUNT'),
|
'lanplace_amount' => env('LAN_PLACE_AMOUNT'),
|
||||||
|
'smsUrl' => env('SMS_URL'),
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
|
||||||
1
resources/views/mail/sms.blade.php
Normal file
1
resources/views/mail/sms.blade.php
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
<p>Hej! Du har fått mail från vBytes angående LAN 2026.</p>
|
||||||
Loading…
Reference in a new issue