first commit
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\PackageName;
|
||||
use App\Models\Reminder;
|
||||
use App\Models\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Kreait\Firebase\Factory;
|
||||
use Kreait\Firebase\Messaging\CloudMessage;
|
||||
|
||||
class SendPushJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public function __construct(
|
||||
public User $user,
|
||||
public $title,
|
||||
public PackageName $packageName,
|
||||
public string $description = '',
|
||||
public array $data = []
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$firebaseFile = $this->getFirebaseJsonPath();
|
||||
|
||||
$factory = (new Factory)
|
||||
->withServiceAccount($firebaseFile);
|
||||
|
||||
$push = $factory->createMessaging();
|
||||
$message = CloudMessage::fromArray([
|
||||
'token' => $this->user->packageNames()->where('package_names.id', $this->packageName->id)->first()->pivot->fcm_token,
|
||||
'notification' => [
|
||||
'title' => $this->title,
|
||||
'body' => $this->description,
|
||||
],
|
||||
'data' => $this->data
|
||||
]);
|
||||
|
||||
$push->send($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Firebase JSON file path from Media Library for the package.
|
||||
*/
|
||||
private function getFirebaseJsonPath(): ?string
|
||||
{
|
||||
$media = $this->packageName->getFirstMedia('firebase_json');
|
||||
|
||||
if (!$media) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $media->getPath();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class SendSMSJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(private $data)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$response = Http::connectTimeout(5)->timeout(5)->get(config('kave.url'), [
|
||||
'receptor' => $this->data['mobile'],
|
||||
'message' => $this->data['message'],
|
||||
'date' => $this->data['date'] ?? null
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user