v1.5.0 Added notifications - Pytlick
This commit is contained in:
@@ -73,7 +73,7 @@ class NewsController extends Controller
|
||||
$news->save();
|
||||
|
||||
Helpers::sendNewsNotification($news, User::query()->where("wants_emails", "=", true)->get());
|
||||
|
||||
PushNotificationController::push();
|
||||
return redirect()->route("news.index");
|
||||
}
|
||||
|
||||
@@ -91,7 +91,7 @@ class NewsController extends Controller
|
||||
$news->save();
|
||||
|
||||
Helpers::sendNewsNotification($news, User::query()->where("wants_emails", "=", true)->get());
|
||||
|
||||
PushNotificationController::push();
|
||||
return $news;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Notification;
|
||||
use App\Notifications\PushNews;
|
||||
use App\User;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class PushNotificationController extends Controller
|
||||
{
|
||||
public function __construct(){
|
||||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store the PushSubscription.
|
||||
*
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function store(Request $request){
|
||||
$this->validate($request,[
|
||||
'endpoint' => 'required',
|
||||
'keys.auth' => 'required',
|
||||
'keys.p256dh' => 'required'
|
||||
]);
|
||||
$endpoint = $request->endpoint;
|
||||
$token = $request->keys['auth'];
|
||||
$key = $request->keys['p256dh'];
|
||||
$user = Auth::user();
|
||||
$user->updatePushSubscription($endpoint, $key, $token);
|
||||
|
||||
return response()->json(['success' => true],200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send Push Notifications to all users.
|
||||
*
|
||||
* @return RedirectResponse
|
||||
*/
|
||||
static public function push(){
|
||||
\Illuminate\Support\Facades\Notification::send(User::all(), new PushNews);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user