Package Data | |
---|---|
Maintainer Username: | hinaloe |
Maintainer Contact: | hina@hinaloe.net (hinaloe) |
Package Create Date: | 2017-05-02 |
Package Last Update: | 2017-05-02 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-26 15:05:52 |
Package Statistics | |
---|---|
Total Downloads: | 1,348 |
Monthly Downloads: | 2 |
Daily Downloads: | 0 |
Total Stars: | 9 |
Total Watchers: | 2 |
Total Forks: | 5 |
Total Open Issues: | 0 |
LINE Notify Provider for Laravel 5.3+ Notification.
install package
$ composer require hinaloe/laravel-line-notify
Add \Hinaloe\LineNotify\LineNotifyServiceProvider
to config/app.php
or like.
Make notifable class (ex User Model entity)
<?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';
}
}
Make notification
<?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
}
}
call $notifable->notify()
$user = User::find(114514);
$user->notify(new NewUserNotification($user));