1. Go to this page and download the library: Download origami/push 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/ */
origami / push example snippets
namespace App;
use Origami\Push\Contracts\Device as PushDevice;
class Device extends Model implements PushDevice {
}
public function getPushService()
{
switch ( $this->make ) {
case 'apple':
case 'ios':
case 'iphone':
return 'apns';
break;
case 'android':
return 'fcm';
break;
default:
throw new \Exception('Unable to determine push service for ' . $this->make);
}
}
public function getPushToken()
{
return $this->device_token;
}
public function routeNotificationForPush()
{
$devices = $this->devices()->get();
return $devices ? $devices->all() : [];
}
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Origami\Push\PushNotification;
class UserJoined extends Notification implements ShouldQueue
{
use Queueable;
public function __construct($user)
{
$this->user = $user;
}
public function via($notifiable)
{
return ['push'];
}
public function toPush($notifiable)
{
return (new PushNotification)
->setTitle('New User')
->setBody($this->user->name . ' just joined')
->setMeta([
'event' => 'NewUser',
'user' => $this->user->id
]);
}
}
$device = new Origami\Push\Device('apns', '12346...');
$push = (new Origami\Push\PushNotification)
->setBody('Testing, testing, 1, 2, 3.');
app('Origami\Push\PushManager')
->driver($device->getPushService())
->send($device, $push);