mirror of
https://github.com/anna-sara/filament_inventory
synced 2026-09-03 10:24:42 +02:00
Fix with mail
This commit is contained in:
parent
0e57494e0b
commit
9e275aeeae
4 changed files with 69 additions and 9 deletions
|
|
@ -32,10 +32,12 @@ use Filament\Support\Enums\TextSize;
|
|||
use Filament\Tables\Columns\Layout\Grid;
|
||||
use Filament\Notifications\Notification;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use App\Mail\ReservationCreatedUser;
|
||||
use App\Mail\ReservationCreated;
|
||||
use Filament\Forms\Components\Checkbox;
|
||||
use Throwable;
|
||||
|
||||
|
||||
class Reserve extends BasePage implements HasTable
|
||||
|
|
@ -202,13 +204,41 @@ class Reserve extends BasePage implements HasTable
|
|||
'phone' => $data['phone']
|
||||
]);
|
||||
Item::where('id', $record->id)->update(['reserved' => true]);
|
||||
|
||||
// The reservation is already saved, so a mail failure must never
|
||||
// take down the response for the visitor.
|
||||
$mailSent = true;
|
||||
|
||||
try {
|
||||
Mail::to($data['email'])
|
||||
->send(new ReservationCreatedUser($reservation));
|
||||
Mail::to(env('MAIL_TO_ADDRESS'))
|
||||
} catch (Throwable $exception) {
|
||||
$mailSent = false;
|
||||
Log::error('Could not send reservation email to the visitor: ' . $exception->getMessage(), [
|
||||
'reservation_id' => $reservation->id,
|
||||
]);
|
||||
}
|
||||
|
||||
if ($adminAddress = config('mail.to_address')) {
|
||||
try {
|
||||
Mail::to($adminAddress)
|
||||
->send(new ReservationCreated($reservation));
|
||||
} catch (Throwable $exception) {
|
||||
Log::error('Could not send reservation email to staff: ' . $exception->getMessage(), [
|
||||
'reservation_id' => $reservation->id,
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
Log::warning('mail.to_address is not set, no reservation email sent to staff.', [
|
||||
'reservation_id' => $reservation->id,
|
||||
]);
|
||||
}
|
||||
|
||||
Notification::make()
|
||||
->title(__('The game is reserved!'))
|
||||
->body(__('A confirmation email has been sent to the address you provided. Read it for more information about collecting the game.'))
|
||||
->body($mailSent
|
||||
? __('A confirmation email has been sent to the address you provided. Read it for more information about collecting the game.')
|
||||
: __('We could not send a confirmation email, but your reservation is registered and we will contact you.'))
|
||||
->success()
|
||||
->seconds(10)
|
||||
->send();
|
||||
|
|
|
|||
|
|
@ -27,9 +27,11 @@ use Filament\Support\Enums\IconPosition;
|
|||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Infolists\Components\ImageEntry;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use App\Mail\ReservationCreatedUser;
|
||||
use App\Mail\ReservationCreated;
|
||||
use Throwable;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
|
|
@ -353,10 +355,24 @@ class ItemResource extends Resource
|
|||
'phone' => $data['phone']
|
||||
]);
|
||||
Item::where('id', $record->id)->update(['reserved' => true]);
|
||||
|
||||
try {
|
||||
Mail::to($data['email'])
|
||||
->send(new ReservationCreatedUser($reservation));
|
||||
Mail::to(env('MAIL_TO_ADDRESS'))
|
||||
|
||||
if ($adminAddress = config('mail.to_address')) {
|
||||
Mail::to($adminAddress)
|
||||
->send(new ReservationCreated($reservation));
|
||||
} else {
|
||||
Log::warning('mail.to_address is not set, no reservation email sent to staff.', [
|
||||
'reservation_id' => $reservation->id,
|
||||
]);
|
||||
}
|
||||
} catch (Throwable $exception) {
|
||||
Log::error('Could not send reservation email: ' . $exception->getMessage(), [
|
||||
'reservation_id' => $reservation->id,
|
||||
]);
|
||||
}
|
||||
})
|
||||
->hidden(fn ($record) => $record->reserved)
|
||||
])
|
||||
|
|
|
|||
|
|
@ -113,4 +113,17 @@ return [
|
|||
'name' => env('MAIL_FROM_NAME', 'Example'),
|
||||
],
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Internal "To" Address
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Address that receives the internal notices, such as a new reservation.
|
||||
| Read it through config() and never through env(), so that it survives
|
||||
| "php artisan config:cache".
|
||||
|
|
||||
*/
|
||||
|
||||
'to_address' => env('MAIL_TO_ADDRESS'),
|
||||
|
||||
];
|
||||
|
|
|
|||
|
|
@ -62,5 +62,6 @@
|
|||
"User": "Användare",
|
||||
"Username": "Namn",
|
||||
"Users": "Användare",
|
||||
"We could not send a confirmation email, but your reservation is registered and we will contact you.": "Vi kunde inte skicka något bekräftelsemail, men din reservation är registrerad och vi hör av oss.",
|
||||
"Welcome! Here you can reserve games that you would like to borrow.": "Välkommen! Här kan du reservera spel som du gärna vill låna."
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue