Files
cheerstothe_season_2.0/app/Http/Helpers/onesignalhelper.php
sayliraut 0903478fde change
2024-07-08 19:47:25 +05:30

88 lines
2.6 KiB
PHP

<?php
namespace App\Helpers;
use App\Models\NotificationDetails;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Carbon\Carbon;
use Ladumor\OneSignal\OneSignal;
class onesignalhelper
{
public static function sendNotificationApi($playerId, $title, $message, $content_type, $imageUrl, $id)
{
// Retrieve configuration based on the specified app
// $config = config("one-signal.apps.$app");
$fields = [
'include_player_ids' => [$playerId],
'contents' => ['en' => $message],
'headings' => ['en' => $title],
'content_available' => true,
'data' => [
'content_type' => $content_type,
'id' => $id,
],
'big_picture' => $imageUrl,
'external_id' => [$playerId]
// 'authorization' => env('ONE_SIGNAL_AUTHORIZE')
];
$result = OneSignal::sendPush($fields, null ,env('ONE_SIGNAL_APP_ID'));
// Log::info($result);
}
public static function restSendNotificationApi($playerId, $title, $message, $content_type, $imageUrl, $id)
{
// Retrieve configuration based on the specified app
// $config = config("one-signal.apps.$app");
$fields = [
'include_player_ids' => [$playerId],
'contents' => ['en' => $message],
'headings' => ['en' => $title],
'content_available' => true,
'data' => [
'content_type' => $content_type,
'id' => $id,
],
'big_picture' => $imageUrl,
// 'app_id' => env('ONE_SIGNAL_APP_ID_2'),
// 'authorization' => env('ONE_SIGNAL_AUTHORIZE_2')
];
$result = OneSignal::sendPush($fields, null, env('ONE_SIGNAL_APP_ID_2'));
}
public static function StoreNotificationDetails($customerId, $type, $description, $imagePath)
{
try {
$currentUtcTime = Carbon::now();
$newRecord = NotificationDetails::create([
'principal_xid' => $customerId,
'type' => $type,
'date_added' => $currentUtcTime,
'description' => $description,
'image' => $imagePath,
]);
} catch (\Exception $e) {
// Return response in case of error
return response()->json([
'status' => 500,
'message' => "Something Went Wrong " . $e->getMessage(),
'result' => null,
'error_code' => 1
]);
}
}
}