PHP code example of relative / laravel-expo-push-notifications

1. Go to this page and download the library: Download relative/laravel-expo-push-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/ */

    

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");
    }

}
 bash
$ php artisan migrate
 bash
$ php artisan vendor:publish --provider="Relative\LaravelExpoPushNotifications\ExpoPushNotificationsServiceProvider"