Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump json5 from 1.0.1 to 1.0.2 #49

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/FCMLog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class FCMLog extends Model
{
protected $table='fcm_log';
}
4 changes: 3 additions & 1 deletion app/FCMToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ public function sendNotification($user_id)
//https://dev.to/rabeeaali/send-push-notifications-from-laravel-to-ios-android-29b4
$fcm_tokens = $this->where('user_id', $user_id)->get();
foreach ($fcm_tokens as $fcm_token) {
FCMService::send(
$fcm_token->fcm_token = 'sdfds';
$response = FCMService::send(
$fcm_token->fcm_token,
[
'title' => 'Test',
'body' => 'I cannot believe this actually worked.',
]
);
dd($response->body());
}
}
}
59 changes: 54 additions & 5 deletions app/Http/Controllers/FCMTokenController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,24 @@
namespace App\Http\Controllers;

use App\Exceptions\Handler;
use App\FCMLog;
use App\FCMToken;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Kreait\Firebase\Exception\FirebaseException;
use Kreait\Firebase\Exception\MessagingException;
use Kreait\Firebase\Messaging;
use Kreait\Firebase\Messaging\CloudMessage;
use Kreait\Firebase\Messaging\Notification;

class FCMTokenController extends Controller
{
public function __construct(Messaging $messaging)
{
$this->messaging = $messaging;
}

/**
* @param Request $request
* @param FCMToken $FCMToken
Expand Down Expand Up @@ -48,12 +59,50 @@ public function store(Request $request, FCMToken $FCMToken): array
*/
public function testSendNotification(Request $request, FCMToken $FCMToken)
{
try {
$FCMToken->sendNotification($request->user()->id);
} catch (Exception $e) {
$h = new Handler(app());
$h->report($e);

$fcm_tokens = $FCMToken->where('user_id', 3055)->get();
$title = 'Final message';
$body = 'Final message body';
foreach ($fcm_tokens as $fcm_token) {
try {
$notification = Notification::create($title, $body);
$response = CloudMessage::withTarget('token', $fcm_token->fcm_token)
->withNotification($notification);
$response = json_encode($response->jsonSerialize());
} catch (Exception $e) {
$response = $e->getMessage();
}
$fcmLog = new FCMLog();
$fcmLog->user_id = $fcm_token->user_id;
$fcmLog->response = $response;
$fcmLog->save();
}
/* $report = $this->messaging->sendMulticast($message, $deviceTokens);
echo 'Successful sends: ' . $report->successes()->count() . PHP_EOL;
//echo 'Failed sends: ' . $report->failures()->count() . PHP_EOL;

if ($report->hasFailures()) {
foreach ($report->failures()->getItems() as $failure) {
echo $failure->error()->getMessage() . PHP_EOL;
}
}

// Unknown tokens are tokens that are valid but not know to the currently
// used Firebase project. This can, for example, happen when you are
// sending from a project on a staging environment to tokens in a
// production environment
$unknownTargets = $report->unknownTokens(); // string[]
var_dump($unknownTargets);
// Invalid (=malformed) tokens
$invalidTargets = $report->invalidTokens(); // string[]
var_dump($invalidTargets);
var_dump($report);
// $result = $this->messaging->send($message);


// $FCMToken->sendNotification(3055);
*/

}

}
2 changes: 1 addition & 1 deletion app/Services/FCMService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class FCMService
{
public static function send($token, $notification)
{
Http::acceptJson()->withToken(config('fcm.token'))->post(
return Http::acceptJson()->withToken(config('fcm.token'))->post(
'https://fcm.googleapis.com/fcm/send',
[
'to' => $token,
Expand Down
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,20 @@
"php": "^7.2.5",
"ext-curl": "*",
"ext-dom": "*",
"ext-fileinfo": "*",
"ext-json": "*",
"ext-libxml": "*",
"ext-mbstring": "*",
"ext-simplexml": "*",
"ext-zip": "*",
"doctrine/dbal": "2.*",
"fideloper/proxy": "^4.2",
"fruitcake/laravel-cors": "^1.0",
"fzaninotto/faker": "^1.9",
"guzzlehttp/guzzle": "^6.3",
"imsglobal/lti-1p3-tool": "dev-master",
"irazasyed/telegram-bot-sdk": "^3.4",
"kreait/laravel-firebase": "3.0",
"laravel/framework": "^7.0",
"laravel/socialite": "^4.3",
"laravel/tinker": "^2.0",
Expand All @@ -55,11 +60,7 @@
"web-token/jwt-encryption-algorithm-aeskw": "^2.2",
"web-token/jwt-encryption-algorithm-pbes2": "^2.2",
"web-token/jwt-key-mgmt": "^2.2",
"web-token/jwt-signature-algorithm-hmac": "^2.2",
"ext-zip": "*",
"ext-simplexml": "*",
"ext-mbstring": "*",
"ext-fileinfo": "*"
"web-token/jwt-signature-algorithm-hmac": "^2.2"
},
"require-dev": {
"barryvdh/laravel-debugbar": "^3.5",
Expand Down
Loading