Skip to content

Commit

Permalink
Add notify macros to LazyUiServiceProvider class
Browse files Browse the repository at this point in the history
The Livewire Component class has been used to define two new macros: notify and notifyFlash in the LazyUiServiceProvider class. These macros will help in managing notifications in the application more efficiently. Now, it's easy to dispatch a notification or flash a notification to the session using these Livewire Component macros.
  • Loading branch information
CrazyBoy49z committed Sep 10, 2023
1 parent 4cc1003 commit b0a9415
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/LazyUiServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Step2dev\LazyUI;

use Livewire\Component;
use Spatie\LaravelPackageTools\Commands\InstallCommand;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
Expand Down Expand Up @@ -49,6 +50,7 @@
use Step2dev\LazyUI\Components\Toast;
use Step2dev\LazyUI\Components\Toggle;
use Step2dev\LazyUI\Components\Tooltip;
use Livewire\Livewire;

class LazyUiServiceProvider extends PackageServiceProvider
{
Expand Down Expand Up @@ -128,4 +130,15 @@ public function configurePackage(Package $package): void
});
});
}

public function packageRegistered(): void
{
Component::macro('notify', function (string $type = 'success', string $message = '', string $title = '') {
$this->dispatch('notify', compact('message', 'title', 'type'));
});

Component::macro('notifyFlash', function (string $type = 'success', string $message = '', string $title = '') {
session()->flash('notify-flash', compact('message', 'title', 'type'));
});
}
}

0 comments on commit b0a9415

Please sign in to comment.