library laravel-line-notify
LINE Notify Provider for Laravel 5 notification
hinaloe/laravel-line-notify
LINE Notify Provider for Laravel 5 notification
- Tuesday, May 2, 2017
- by hinaloe
- Repository
- 2 Watchers
- 5 Stars
- 458 Installations
- PHP
- 0 Dependents
- 0 Suggesters
- 1 Forks
- 0 Open issues
- 2 Versions
- 2 % Grown
Laravel5 LINE Notify Provider
LINE Notify Provider for Laravel 5.3+ Notification., (*1)
Requirements
- PHP 7.0+
- Laravel 5.3+ (Recommend 5.4+)
Usage
-
install package, (*2)
$ composer require hinaloe/laravel-line-notify
-
Add \Hinaloe\LineNotify\LineNotifyServiceProvider to config/app.php or like., (*3)
-
Make notifable class (ex User Model entity), (*4)
<?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, (*5)
<?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(), (*6)
$user = User::find(114514);
$user->notify(new NewUserNotification($user));
dev-master
9999999-dev
LINE Notify Provider for Laravel 5 notification
Sources
Download
MIT
The Requires
by
hinaloe
v0.0.1
0.0.1.0
LINE Notify Provider for Laravel 5 notification
Sources
Download
MIT
The Requires
by
hinaloe