PHP code example of chijioke-ibekwe / raven

1. Go to this page and download the library: Download chijioke-ibekwe/raven 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/ */

    

chijioke-ibekwe / raven example snippets


   

    return [
    
        'default' => [
            'email' => env('EMAIL_NOTIFICATION_PROVIDER', 'sendgrid'),
            'sms' => env('SMS_NOTIFICATION_PROVIDER', 'vonage')
        ],
    
        'providers' => [
            'sendgrid' => [
                'key' => env('SENDGRID_API_KEY')
            ],
            'ses' => [
                'key' => env('AWS_ACCESS_KEY_ID'),
                'secret' => env('AWS_SECRET_ACCESS_KEY'),
                'region' => env('AWS_DEFAULT_REGION', 'us-east-1')
            ],
            'vonage' => [
                'api_key' => env('VONAGE_API_KEY'),
                'api_secret' => env('VONAGE_API_SECRET')
            ],
            'twilio' => [
                'account_sid' => env('TWILIO_ACCOUNT_SID'),
                'auth_token' => env('TWILIO_AUTH_TOKEN')
            ],
            'postmark' => [
                'token' => env('POSTMARK_API_TOKEN')
            ],
            'mailgun' => [
                'secret' => env('MAILGUN_SECRET'),
                'domain' => env('MAILGUN_DOMAIN'),
                'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net')
            ]
        ],

        'customizations' => [
            'email' => [
                'from' => [
                    'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
                    'name' => env('MAIL_FROM_NAME', 'Example'),
                ]
            ],
            'sms' => [
                'from' => [
                    'name' => env('SMS_FROM_NAME', 'Example'),
                    'phone_number' => env('SMS_FROM_PHONE_NUMBER'),
                ]
            ],
            'queue_name' => env('RAVEN_QUEUE_NAME'),
            'queue_connection' => env('RAVEN_QUEUE_CONNECTION'),
            'templates_directory' => env('TEMPLATES_DIRECTORY', resource_path('templates'))
        ]
    ];
    

    // config/notification-contexts.php
    return [
        'user-verified' => [
            'description'       => 'Notification to inform a user that they have been verified on the platform',
            'email_template_id' => env('TEMPLATE_USER_VERIFIED', 'd-ad34ghAwe3mQRvb29'),
            'channels'          => ['email'],
            'active'            => true,
        ],
    ];
    

    // config/notification-contexts.php
    return [
        'user-verified' => [
            'description'             => 'Notification to inform a user that they have been verified on the platform',
            'email_template_filename' => 'user-verified.html',
            'email_subject'           => 'Welcome, {{name}}! Your account has been verified',
            'channels'                => ['email'],
            'active'                  => true,
        ],
    ];
    

    // config/notification-contexts.php
    return [
        'user-verified' => [
            'description'          => 'Notification to inform a user that they have been verified on the platform',
            'sms_template_filename' => 'user-verified.txt',
            'channels'             => ['sms'],
            'active'               => true,
        ],
    ];
    

    // config/notification-contexts.php
    return [
        'user-verified' => [
            'description'              => 'Notification to inform a user that they have been verified on the platform',
            'in_app_template_filename' => 'user-verified.json',
            'channels'                 => ['database'],
            'active'                   => true,
        ],
    ];
    

    // config/notification-contexts.php
    return [
        'user-verified' => [
            'description'              => 'Notification to inform a user that they have been verified on the platform',
            'email_template_id'        => env('TEMPLATE_USER_VERIFIED', 'd-ad34ghAwe3mQRvb29'),
            'sms_template_filename'    => 'user-verified.txt',
            'in_app_template_filename' => 'user-verified.json',
            'channels'                 => ['email', 'sms', 'database'],
            'active'                   => true,
        ],
    ];
    

    // config/notification-contexts.php
    return [
        'password-reset' => [
            'description'             => 'Password reset OTP notification',
            'email_template_filename' => 'password-reset.html',
            'email_subject'           => 'Reset your password',
            'sms_template_filename'   => 'password-reset.txt',
            'channels'                => ['email', 'sms'],
            'active'                  => true,
            'encrypted'               => true,
            'queue'                   => [
                'email' => ['queue' => 'critical', 'connection' => 'sqs'],
                'sms'   => ['queue' => 'critical'],
            ],
        ],
    ];
    

           $verified_user = User::find(1);
           $document_url = "https://example.com/laravel-cheatsheet.pdf";

           $scroll = Scroll::make()
               ->for('user-verified')
               ->to([$verified_user, '[email protected]'])
               ->cc(['[email protected]' => 'John Doe', '[email protected]' => 'Jane Doe'])
               ->bcc(['[email protected]' => 'Audit Team'])
               ->replyTo('[email protected]')
               ->with([
                   'id' => $verified_user->id,
                   'name' => $verified_user->name,
                   'email' => $verified_user->email
               ])
               ->attach($document_url);

           Raven::dispatch($scroll);
   

             use Illuminate\Notifications\Notifiable;
             use Illuminate\Foundation\Auth\User as Authenticatable;
         
             class User extends Authenticatable
             {
                 use Notifiable;
     
                 public function routeNotificationForMail()
                 {
                     return $this->email_address;
                 }
             }
     

   $scroll = Scroll::make()
       ->for('user-verified')
       ->to($user)
       ->channels(['email'])  // only send email, even if context defines sms and database too
       ->with(['name' => $user->name]);

   Raven::dispatch($scroll);
   

   $scroll = Scroll::make()
       ->for('password-reset')
       ->to($user)
       ->sync()
       ->with(['otp' => $otp]);

   Raven::dispatch($scroll);
   

   // Delay all channels by 60 seconds
   $scroll = Scroll::make()
       ->for('order-confirmed')
       ->to($user)
       ->delay(60)
       ->with(['order_id' => $order->id]);

   // Per-channel delay: email in 30 minutes, SMS immediately
   $scroll = Scroll::make()
       ->for('order-confirmed')
       ->to($user)
       ->delay([
           'email' => now()->addMinutes(30),
           'sms'   => 0,
       ])
       ->with(['order_id' => $order->id]);

   Raven::dispatch($scroll);
   

   DB::transaction(function () use ($user) {
       $user->update(['verified' => true]);

       $scroll = Scroll::make()
           ->for('user-verified')
           ->to($user)
           ->afterCommit()
           ->with(['name' => $user->name]);

       Raven::dispatch($scroll);
   });
   

   use ChijiokeIbekwe\Raven\Events\RavenNotificationSent;
   use ChijiokeIbekwe\Raven\Events\RavenNotificationFailed;

   // In EventServiceProvider::$listen
   protected $listen = [
       RavenNotificationSent::class => [
           \App\Listeners\LogNotificationSuccess::class,
       ],
       RavenNotificationFailed::class => [
           \App\Listeners\LogNotificationFailure::class,
       ],
   ];
   
bash
    php artisan vendor:publish --provider="ChijiokeIbekwe\Raven\RavenServiceProvider" --tag=raven-config
    php artisan vendor:publish --provider="ChijiokeIbekwe\Raven\RavenServiceProvider" --tag=raven-contexts
    
bash
   php artisan raven:make-context
   
bash
    php artisan notifications:table
    
bash
    php artisan migrate