hinaloe / laravel-line-notify
Laravel 5 通知的 LINE Notify 提供程序
v0.0.1
2017-05-02 19:39 UTC
Requires
- php: >=7.0
- guzzlehttp/guzzle: ~6.0
- illuminate/notifications: ^5.3
This package is auto-updated.
Last update: 2024-09-11 17:05:10 UTC
README
Laravel 5.3+ 通知的 LINE Notify 提供程序。
要求
- PHP 7.0+
- Laravel 5.3+(推荐 5.4+)
使用方法
-
安装包
$ composer require hinaloe/laravel-line-notify
-
将
\Hinaloe\LineNotify\LineNotifyServiceProvider
添加到config/app.php
或类似文件。 -
制作可通知的类(例如用户模型实体)
<?php namespace App; use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { use Notifiable; // ... /** * @return string LINE Notify OAuth2 token */ protected function routeNotificationForLine() { return 'hogehogehoge'; } }
-
制作通知
<?php namespace App\Notifications; use App\User; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Notifications\Notification; use Hinaloe\LineNotify\Message\LineMessage; class NewUserNotification extends Notification// implements ShouldQueue { use Queueable; /** @var User */ protected $user; /** * Create a new notification instance. * * @param User $user */ public function __construct(User $user) { $this->user = $user; } /** * Get the notification's delivery channels. * * @param mixed $notifiable * * @return array */ public function via($notifiable) { return ['line']; } /** * @param mixed $notifable callee instance * @return LineMessage */ public function toLine($notifable) { return (new LineMessage())->message('New user: ' . $this->user->name) ->imageUrl('https://example.com/sample.jpg') // With image url (jpeg only) ->imageFile('/path/to/image.png') // With image file (png/jpg/gif will convert to jpg) ->sticker(40, 2); // With Sticker } }
-
调用
$notifable->notify()
$user = User::find(114514); $user->notify(new NewUserNotification($user));