fcorz / laravel-line-notify
My awesome package
1.0.0
2021-02-25 03:38 UTC
Requires
- php: ^7.2
- guzzlehttp/guzzle: ^6.3|^7.0.1
- illuminate/notifications: ^6.0|^7.0|^8.0
- illuminate/support: ^5.8|^6.0|^7.0|^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.14
- orchestra/testbench: ^3.8|^4.0|^5.0|^6.0
- phpunit/phpunit: ^7.0|^8.0|^9.0
README
🌈 laravel line notify notification
Laravel implements the line notify message notification function. Including the binding of code in exchange for access token and notification channel message push.
Installation
you can install the package via composer:
composer require fcorz/laravel-line-notify
publish config
php artisan vendor:publish --provider="Fcorz\LaravelLineNotify\LaravelLineNotifyServiceProvider"
Usage
simple
// get access_token by code app('line-notify')->getAccessToken("O97YoWeYMV6vW3uYPFgPAC"); // response { "status":200, "message":"access_token is issued", "access_token":"1vIvPoq4aG4UOJYoQ6oriAUPvDNxxxxxxxxxxx" } // notify $message = (new LaravelLineMessage())->message('hello world'); app('line-notify')->sendNotify($message, "access_token");
facade
// get access_token by code LaravelLineNotifyFacade::getAccessToken("O97YoWeYMV6vW3uYPFgPAC"); // notify $message = (new LaravelLineMessage())->message('hello world'); LaravelLineNotifyFacade::sendNotify($message, "access_token");
notification
user model notifiable
public function routeNotificationForLine($notification) { return $this->notify_access_token; }
create your notification ( you can also not use the queue )
use App\Models\UserMessage; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Support\Facades\Notification; class LineNotification extends Notification implements ShouldQueue { use Queueable; protected $message; public function __construct($message, $delay = 0) { $this->queue = 'notification'; $this->delay = $delay; $this->message = $message; } /** * Get the notification's delivery channels. * * @param mixed $notifiable * @return array */ public function via($notifiable) { return ['line']; } /** * @param $notifable * @return LineTemplateService */ public function toLineNotify($notifable) { return (new LaravelLineMessage())->message($this->message); } }
call notify()
$receiver->notify(new LineNotification('hello world'));
Security
If you discover any security related issues, please email fengchenorz@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.