UserCertifyObserver.php
974 Bytes
<?php
namespace App\Observers;
use App\Helpers\UploadHelper;
use App\Jobs\MediaTranscodeJob;
use App\Models\UserCertify;
use Illuminate\Support\Str;
class UserCertifyObserver
{
/**
* @param \App\Models\UserCertify $certify
* @return void
* @throws \JsonException
*/
public function created(UserCertify $certify): void
{
$localUrl = data_get($certify, 'audio_info.local');
if ($localUrl && !Str::endsWith($localUrl, 'mp3')) {
MediaTranscodeJob::dispatch($localUrl, [
"TemplateId" => "S00000001-300050",
"OutputObject" => UploadHelper::getFileName('audio') . '.mp3',
"UserData" => json_encode([
'event_id' => $certify->getKey(),
'event_type' => class_basename($certify),
'event_attribute' => 'audio_info->local'
], JSON_THROW_ON_ERROR)
]);
}
}
}