add notifications
This commit is contained in:
1 parent
1913eabc00
commit
01be3b34ad
26 files changed
+319
-149
No files matched your search
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Mail\UserNotification;
|
||||
use App\Models\User;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\Concerns\InteractsWithActions;
|
||||
use Filament\Actions\Contracts\HasActions;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Schemas\Concerns\InteractsWithSchemas;
|
||||
use Filament\Schemas\Contracts\HasSchemas;
|
||||
use Filament\Support\Enums\Width;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Concerns\InteractsWithTable;
|
||||
use Filament\Tables\Contracts\HasTable;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Livewire\Component;
|
||||
|
||||
class UserNotifications extends Component implements HasActions, HasSchemas, HasTable
|
||||
{
|
||||
use InteractsWithActions;
|
||||
use InteractsWithSchemas;
|
||||
use InteractsWithTable;
|
||||
|
||||
public function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->query(User::query())
|
||||
->columns([
|
||||
TextColumn::make('name')->icon('phosphor-user-duotone')->searchable(),
|
||||
TextColumn::make('email')->icon('phosphor-envelope-duotone'),
|
||||
])
|
||||
->filters([
|
||||
// ...
|
||||
])
|
||||
->recordActions([
|
||||
Action::make('notification')
|
||||
->icon('phosphor-note-pencil-duotone')
|
||||
->tooltip('Create a notification')
|
||||
->modalHeading(fn ($record) => 'Send a notification to '.$record->name)
|
||||
->iconButton()
|
||||
->modalWidth(Width::Large)
|
||||
// ->modalDescription('Send a notification')
|
||||
->modalSubmitActionLabel('Send')
|
||||
->modalIcon('phosphor-envelope-duotone')
|
||||
->schema([
|
||||
Textarea::make('message')
|
||||
->rows(4),
|
||||
Toggle::make('notify_by_email')->label('Send also as email')
|
||||
// ->belowContent('Notify me also by e-mail')
|
||||
->onColor('info')
|
||||
->offColor('gray'),
|
||||
])->action(function (array $data, $record) {
|
||||
if ($data['notify_by_email']) {
|
||||
Mail::to($record)
|
||||
->send(new UserNotification($data['message']));
|
||||
}
|
||||
Notification::make()
|
||||
->title('Saved successfully')
|
||||
->icon('phosphor-paper-plane-right')
|
||||
->body($data['message'])
|
||||
->sendToDatabase($record);
|
||||
}),
|
||||
|
||||
])
|
||||
->toolbarActions([
|
||||
// ...
|
||||
]);
|
||||
}
|
||||
|
||||
public function render(): View
|
||||
{
|
||||
return view('livewire.user-notifications');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user