PHP code example of cjpanilag / simple-notifications
1. Go to this page and download the library: Download cjpanilag/simple-notifications 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/ */
cjpanilag / simple-notifications example snippets
use Cjpanilag\SimpleNotifications\Traits\HasSnsNotifiableTrait;
class User extends Authenticatable
{
use HasApiTokens, HasFactory, HasSnsNotifiableTrait;
/**
* Overridden method (optional)
* By default, `SnsNoticiableTrait` will look
* for the specific attribute in your model:
* `phone`,
* `phone_number`,
* `full_phone`
*
* @override
* @param $notification
* @return string|null
*/
public function routeNotificationForSns($notification): string|null
{
// model attribute
return $this->specific_mobile_number_attribute;
}
}
// Sending SMS to a User model...
$user = User::first();
simpleNotifications()->sns()
->user($user)
->content('Message here...')
->execute();
// Sending SMS to a specific phone...
simpleNotifications()->sns()
->mobile('+639123456789')
->content('Message here...')
->execute();
// Sending SMS to a User model...
$user = User::first();
simpleNotifications()->sns()
->user($user)
->content(fn($user) => "Welcome $user->name") // passing notifiable
->execute();
// Sending SMS to a specific phone...
simpleNotifications()->sns()
->mobile('+639123456789')
->content(fn($user) => "Welcome $user->name") // passing notifiable
->execute();
// Sending SMS to a User model...
$user = User::first();
simpleNotifications()->sns()->user($user)->content(function ($user) {
$snsMessage = new SnsMessage('message here...');
$snsMessage->sender('FIN-PAY');
$snsMessage->transactional(true);
return $snsMessage;
})->execute();
// Sending SMS to a specific phone...
simpleNotifications()->sns()->mobile('+639123456789')->content(function ($user) {
$snsMessage = new SnsMessage('message here...');
$snsMessage->sender('FIN-PAY');
$snsMessage->transactional(true);
return $snsMessage;
})->execute();
simpleNotifications()->sns()
->user($user) // User already have <mobile number attribute>...
->mobile('+63923456789') // Will conflict with User mobile number attribute...
->content('Message here...')
->execute();
use Cjpanilag\SimpleNotifications\Traits\HasMailNotifiableTrait;
class Model extends Authenticatable
{
use HasApiTokens, HasFactory, HasMailNotifiableTrait;
/**
* @param $notification
* @return array|string|null
*/
public function routeNotificationForMail($notification): array|string|null
{
// Define a specific <email attribute>
return $this->email_address;
}
}
// Sending mail to a User model...
$user = User::first();
simpleNotifications()->mail()
->user($user)
->subject('Test Subject 123')
->body('test body')
->footer('test footer')
->actionMessage('PUSH ME!')
->actionUrl('http://localhost')
->execute();
// Sending mail to a specific email address...
simpleNotifications()->mail()
->emailAddress('[email protected]')
->subject('Test Subject 123')
->body('test body')
->footer('test footer')
->actionMessage('PUSH ME!')
->actionUrl('http://localhost')
->execute();
// Sending mail to a User model...
$user = User::first();
simpleNotifications()->mail()->user($user)->content(function ($user) {
$mailMessage = new MailMessage();
$subject = 'test subject 2';
if ($user) {
$mailMessage->subject($subject);
}
$mailMessage->line('this is a best body number 2')
->action('PUSH ME!', 'https://test.com')
->line('this is a test footer 2');
return $mailMessage;
})->execute();
// Sending mail to a specific email address...
// Sending mail to a specific email address...
simpleNotifications()->mail()->emailAddress('[email protected]')->content(function ($user) {
$mailMessage = new MailMessage();
$mailMessage->view('view.template');
return $mailMessage;
})->execute();
$user = User::first();
simpleNotifications()->mail()
->user($user) // user has email attribute
->emailAddress('[email protected]') // conflict with email attribute
->subject('Test Subject 123')
->body('test body')
->footer('test footer')
->actionMessage('PUSH ME!')
->actionUrl('http://localhost')
->execute();