Skip to content

Commit

Permalink
move notification macro to main provider
Browse files Browse the repository at this point in the history
  • Loading branch information
3x1io committed Nov 25, 2024
1 parent b538b58 commit 797734b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
16 changes: 0 additions & 16 deletions src/FilamentAlertsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public function register(Panel $panel): void
EmailSettingsPage::class,
]);
}

}

public function hideNotificationsResource(?bool $hideNotificationsResource = true): static
Expand Down Expand Up @@ -114,21 +113,6 @@ public function boot(Panel $panel): void
}
}

Notification::macro('sendUse', function (Model $user, string $driver = EmailDriver::class, array $data = []): static {
/** @var Notification $this */
app($driver)->sendIt(
title: $this->getTitle(),
body: $this->getBody(),
icon: $this->getIcon(),
type: $this->getStatus(),
url: count($this->getActions()) ? $this->getActions()[0]->getUrl() ?? null : null,
model: get_class($user),
modelId: $user->id
);

return $this;
});

if (config('filament-alerts.predefined.users')) {
FilamentAlerts::register(
NotificationUser::make(config('filament-alerts.try.model'))
Expand Down
18 changes: 18 additions & 0 deletions src/FilamentAlertsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

namespace TomatoPHP\FilamentAlerts;

use Filament\Notifications\Notification;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\ServiceProvider;
use TomatoPHP\FilamentAlerts\Services\Drivers\EmailDriver;
use TomatoPHP\FilamentAlerts\Services\NotificationService;

class FilamentAlertsServiceProvider extends ServiceProvider
Expand Down Expand Up @@ -49,6 +52,21 @@ public function register(): void
$this->app->bind('filament-alerts', function () {
return new NotificationService;
});

Notification::macro('sendUse', function (Model $user, string $driver = EmailDriver::class, array $data = []): static {
/** @var Notification $this */
app($driver)->sendIt(
title: $this->getTitle(),
body: $this->getBody(),
icon: $this->getIcon(),
type: $this->getStatus(),
url: count($this->getActions()) ? $this->getActions()[0]->getUrl() ?? null : null,
model: get_class($user),
modelId: $user->id
);

return $this;
});
}

public function boot(): void {}
Expand Down

0 comments on commit 797734b

Please sign in to comment.