Merge pull request 'change dlogin in web.php and added web push subscription model file' (#137) from ranjith-dev into master
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 13s
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 13s
Reviewed-on: #137
This commit was merged in pull request #137.
This commit is contained in:
19
app/Models/WebPushSubscription.php
Normal file
19
app/Models/WebPushSubscription.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class WebPushSubscription extends Model
|
||||
{
|
||||
protected $table = 'push_subscriptions';
|
||||
|
||||
protected $fillable = [
|
||||
'subscribable_type',
|
||||
'subscribable_id',
|
||||
'endpoint',
|
||||
'public_key',
|
||||
'auth_token',
|
||||
'content_encoding',
|
||||
];
|
||||
}
|
||||
@@ -6,6 +6,7 @@ use App\Models\EquipmentMaster;
|
||||
use App\Models\InvoiceValidation;
|
||||
use App\Models\Plant;
|
||||
use App\Models\User;
|
||||
use App\Models\WebPushSubscription;
|
||||
use Filament\Facades\Filament;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
@@ -31,20 +32,46 @@ use App\Http\Livewire\CustomLogin;
|
||||
// return response()->json(['success' => true]);
|
||||
// })->middleware('auth');
|
||||
|
||||
Route::post('/push/subscribe', function (Request $request) {
|
||||
$user = Filament::auth()->user();
|
||||
// Route::post('/push/subscribe', function (Request $request) {
|
||||
// $user = Filament::auth()->user();
|
||||
|
||||
// abort_if(!$user, 401);
|
||||
|
||||
// $user->updatePushSubscription(
|
||||
// $request->endpoint,
|
||||
// $request->keys['p256dh'],
|
||||
// $request->keys['auth'],
|
||||
// $request->contentEncoding ?? 'aesgcm'
|
||||
// );
|
||||
|
||||
// return response()->json(['success' => true]);
|
||||
// });
|
||||
|
||||
Route::post('/push/subscribe', function (Request $request) {
|
||||
|
||||
$user = Filament::auth()->user();
|
||||
abort_if(!$user, 401);
|
||||
|
||||
$user->updatePushSubscription(
|
||||
$request->endpoint,
|
||||
$request->keys['p256dh'],
|
||||
$request->keys['auth'],
|
||||
$request->contentEncoding ?? 'aesgcm'
|
||||
$request->validate([
|
||||
'endpoint' => 'required|string',
|
||||
'keys.p256dh' => 'required|string',
|
||||
'keys.auth' => 'required|string',
|
||||
]);
|
||||
|
||||
WebPushSubscription::updateOrCreate(
|
||||
// ✅ UNIQUE PER DEVICE
|
||||
['endpoint' => $request->endpoint],
|
||||
[
|
||||
'subscribable_type' => get_class($user), // 🔥 important
|
||||
'subscribable_id' => $user->id,
|
||||
'public_key' => $request->keys['p256dh'],
|
||||
'auth_token' => $request->keys['auth'],
|
||||
'content_encoding' => $request->contentEncoding ?? 'aesgcm',
|
||||
]
|
||||
);
|
||||
|
||||
return response()->json(['success' => true]);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// routes/web.php
|
||||
|
||||
Reference in New Issue
Block a user