PHP code example of trin4ik / laravel-expo-push

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

    

trin4ik / laravel-expo-push example snippets




namespace App\Models;

// ...

class User extends Authenticatable
{
    use Notifiable;

    // ...

    public function routeNotificationForExpoPush () {
        return $this->expo_token; // like ExponentPushToken[XXXXXXX_XXXXXXXXXXXXXX]
    }
}



namespace App\Models;

class ExpoPushNotification extends Trin4ik\LaravelExpoPush\Models\ExpoPushNotification {
    protected $table = 'my_custom_notifications_table';
}

return [
    // ...
    'log' => [
        // ...
        'driver' => [
            // ...
            'instance' => \App\Models\ExpoPushNotification::class
        ]
    ]
];



namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
use Trin4ik\LaravelExpoPush\Channels\ExpoPushChannel;
use Trin4ik\LaravelExpoPush\ExpoPush;

class PushTest extends Notification implements ShouldQueue
{
    use Queueable;
    
    public function via($notifiable)
    {
        return [ExpoPushChannel::class];
    }

    public function toExpoPush($notifiable) {
        return ExpoPush::create()
            ->badge(1)
            ->title("Congratulations!")
            ->body("Your " . $notifiable->email . " account was approved!");
    }
}


use App\Notifications\PushTest;
use App\Models\User;

// ...

$user = User::find(1);
$user->notify(new PushTest);



namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;
use Trin4ik\LaravelExpoPush\Channels\ExpoPushChannel;

class PushTest extends Notification implements ShouldQueue
{
    use Queueable;
    
    public function via($notifiable)
    {
        return [ExpoPushChannel::class];
    }

    public function toArray($notifiable) {
        return [
            'badge' => 1,
            'title' => "Congratulations!",
            'body' => "Your " . $notifiable->email . " account was approved!",
            'new_expo_notification_param' => true
        ];
    }
}
bash
composer vendor:publish --provider "Trin4ik\LaravelExpoPush\ExpoPushServiceProvider"
bash
echo "EXPO_PUSH_LOG=true" >> .env
php artisan migrate
bash
php artisan make:notification PushTest