PHP code example of laravelwudel / laravelwudel-notif

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

    

laravelwudel / laravelwudel-notif example snippets


use LaravelWudel\LaravelWudelNotif\Facades\PushNotification;

// Kirim notifikasi ke user tertentu
PushNotification::sendToUser($user, 'Judul', 'Pesan notifikasi');

// Kirim notifikasi ke semua user
PushNotification::sendToAll('Judul', 'Pesan broadcast');

// Kirim dengan data tambahan
PushNotification::sendToUser($user, 'Judul', 'Pesan', [
    'url' => '/dashboard',
    'action' => 'view'
]);

use LaravelWudel\LaravelWudelNotif\Services\WebPushService;

class NotificationController extends Controller
{
    public function __construct(private WebPushService $pushService) {}

    public function sendNotification(Request $request)
    {
        $user = auth()->user();
        $sent = $this->pushService->sendToUser(
            $user,
            $request->title,
            $request->message
        );

        return response()->json(['sent' => $sent]);
    }
}

// User model
public function pushSubscriptions()
{
    return $this->hasMany(PushSubscription::class);
}

// PushSubscription model
public function user()
{
    return $this->belongsTo(User::class);
}
bash
php artisan vendor:publish --provider="LaravelWudel\LaravelWudelNotif\LaravelWudelNotifServiceProvider"
bash
php artisan migrate
bash
php artisan push:generate-vapid-keys
bash
php artisan push:generate-vapid-keys
bash
php artisan push:cleanup-subscriptions
bash
rm config/laravelwudel-notif.php
bash
# Rollback migration terlebih dahulu
php artisan migrate:rollback --step=1

# Hapus file migration
rm database/migrations/*_create_push_subscriptions_table.php
bash
rm app/Models/PushSubscription.php
bash
composer dump-autoload
bash
# Hapus semua cache Laravel
rm -rf bootstrap/cache/*

# Clear compiled classes
php artisan clear-compiled

# Rebuild autoload
composer dump-autoload

# Clear semua cache
php artisan optimize:clear
bash
# Jalankan emergency cleanup
php artisan laravelwudel-notif:uninstall --force

# Atau hapus semua cache secara manual
rm -rf bootstrap/cache/*
composer install
php artisan optimize:clear