1. Go to this page and download the library: Download patienceman/synca 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/ */
patienceman / synca example snippets
> QUEUE_CONNECTION=database
>
App\Notifiers
namespace App\Notifications;
use Patienceman\Synca\NotifyHandler;
class EmailNotification extends NotifyHandler {
/**
* Execute notification actions
*
* @return mixed
*/
public function handle() {
// do whatever action inside handler
}
}
namespace App\Http\Controllers;
use App\Notifications\EmailNotification;
use Patienceman\Synca\Facades\Notifier;
class UsersController extends Controller {
/**
* Handle User Notifications
*/
public function notifications(Notifier $notifier) {
// ... Other Codes
$notifier->handle([
EmailNotification::process([
'message' => 'Application sent to job sent'
]),
]);
}
}
namespace App\Http\Controllers;
use App\Notifications\EmailNotification;
use Patienceman\Synca\Facades\Notifier;
class UsersController extends Controller {
/**
* Handle User Notifications
*/
public function notifications(Notifier $notifier, User $user) {
// ... Other Codes
$application = Application::findById('1')->belongsToCompany()->user_id;
$notification = [ 'message' => 'Application sent to job sent' ];
$users = [
'user' => $user
'applicant' => $application
];
$notifier->handle([
EmailNotification::process($notification)
->to($users)
->onQueue(),
]);
}
}
$this->user;
$this->applicant;
namespace App\Http\Controllers;
use App\Notifications\EmailNotification;
use App\Notifications\OneSignalNotification;
use Patienceman\Synca\Facades\Notifier;
class UsersController extends Controller {
public function notifications(Notifier $notifier, User $user) {
$application = Application::findById('1')->belongsToCompany()->user_id;
$notification = [ 'message' => 'Application sent to job sent' ];
$users = [
'user' => $user
'applicant' => $application
];
$notifier->handle([
EmailNotification::process($notification)->to($users),
OneSignalNotification::process($notification)->to([$user]),
])->onQueue();
}
}
namespace App\Notifications;
use Patienceman\Synca\NotifyHandler;
class EmailNotification extends NotifyHandler {
/**
* Execute notification actions
* @return mixed
*/
public function handle() {
$this->message; // this will get single passed payload
$this->payload(); // this will get all payload as object
$this->recipients(); // this will get all targeted users
}
}