Laravel Desktop Notifier is a package by Nuno Maduro to send notifications to your desktop from Artisan commands:
1public function handle() 2{ 3 $this->notify('Hello Web Artisan', 'Love beautiful code? We do too!'); 4 // Icons anyone? 5 $this->notify( 6 'With a logo!', 7 'This has a logo', 8 resource_path('path/to/icon.png') 9 );10}
The first example would look something like this on macOS:
Under the hood, this package uses the a macro to add the notify method to console commands:
1Command::macro('notify', function (string $text, string $body, $icon = null) { 2 $notifier = $this->laravel[Contracts\Notifier::class]; 3 4 $notification = $this->laravel[Contracts\Notification::class] 5 ->setTitle($text) 6 ->setBody($body); 7 8 if ( ! empty($icon)) { 9 $notification->setIcon($icon);10 }11 12 $notifier->send($notification);13});
As you can see, the first argument is the notification title, followed by the notification body and the optional icon.
If you’re interested in integrating desktop notifications in a PHP package, this package uses the excellent JoliNotif. Desktop notifications work across Linux, Windows, and macOS!
You can learn more about this package, get full installation instructions, and view the source code on GitHub.
0 comments:
Post a Comment
Thanks