PHP code example of rc1021 / laravel-line-notify

1. Go to this page and download the library: Download rc1021/laravel-line-notify library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

rc1021 / laravel-line-notify example snippets


   
    
   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 '{LINE Notify OAuth2 token}';
       }
   }
    
    

    
    
    namespace App\Notifications;
    
    use App\User;
    use Illuminate\Bus\Queueable;
    use Illuminate\Contracts\Queue\ShouldQueue;
    use Illuminate\Notifications\Notification;
    use Rc1021\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
        }
    }
    

    $user = User::find(114514);
    $user->notify(new NewUserNotification($user));