<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
relative / laravel-expo-push-notifications example snippets
use Relative\LaravelExpoPushNotifications\Traits\HasPushTokens;
class User {
use Notifiable, HasPushTokens;
//
}
class PushNotificationController extends \Illuminate\Routing\Controller {
public function register(Request $request)
{
$token = $request->input('token');
$request->user()->pushTokens()->firstOrCreate(
['token' => $token],
['token' => $token],
);
return response()->status(200);
}
}
use Illuminate\Bus\Queueable;
use Relative\LaravelExpoPushNotifications\ExpoPushNotifications;
use Relative\LaravelExpoPushNotifications\PushNotification;
class NewOrder extends \Illuminate\Notifications\Notification {
use Queueable;
public $order;
/**
* Create a new notification instance.
*
* @param $order
*/
public function __construct($order)
{
$this->order = $order;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return [ExpoPushNotifications::class];
}
public function toExpoPushNotification($notifiable)
{
return (new PushNotification)
->title('New order received')
->body("Order #{$this->order->id} is ready for processing");
}
}