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\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
];
}
}