generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
SupportBubbleServiceProvider.php
51 lines (44 loc) · 1.81 KB
/
SupportBubbleServiceProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace Spatie\SupportBubble;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Facades\Route;
use Spatie\Honeypot\ProtectAgainstSpam;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
use Spatie\SupportBubble\Components\SupportBubbleComponent;
use Spatie\SupportBubble\Events\SupportBubbleSubmittedEvent;
use Spatie\SupportBubble\Http\Controllers\HandleSupportBubbleSubmissionController;
use Spatie\SupportBubble\Notifications\BubbleResponseNotification;
class SupportBubbleServiceProvider extends PackageServiceProvider
{
public function configurePackage(Package $package): void
{
$package
->name('laravel-support-bubble')
->hasConfigFile()
->hasTranslations()
->hasViews();
}
public function packageBooted()
{
Blade::component('support-bubble', SupportBubbleComponent::class);
Blade::component('input-field', 'support-bubble::components.input-field', 'support-bubble');
Route::macro('supportBubble', function (string $url = '') {
Route::post("{$url}/support-bubble", HandleSupportBubbleSubmissionController::class)
->name(config('support-bubble.form_action_route'))
->middleware(ProtectAgainstSpam::class);
});
if (config('support-bubble.mail_to')) {
$this->registerMailNotificationEventHandler();
}
}
protected function registerMailNotificationEventHandler(): void
{
Event::listen(function (SupportBubbleSubmittedEvent $event) {
Notification::route('mail', config('support-bubble.mail_to'))
->notify(BubbleResponseNotification::fromEvent($event));
});
}
}