This commit is contained in:
ivan-sim
2024-10-04 10:46:03 +07:00
parent 2663a7bfbe
commit 8d5c7e4cb4
2 changed files with 28 additions and 20 deletions

View File

@@ -197,6 +197,29 @@ class ApotekController extends Controller
'tx_prescription_orders.sDeliveryStatus'
)
->paginate($limit);
// Secret key for generating the token
$secret_key = env('SECRET_KEY_LMS');
// Transform the results to include the download link
$results->getCollection()->transform(function ($item) use ($secret_key) {
// Generate the token with the timestamp
$expiry_time = time() + 86400; // Token expiry time (1 day)
$token = hash_hmac('sha256', $item->id . $expiry_time, $secret_key);
// Construct the download link
$path = 'prescription/barcode-print-pdf/' . $item->id . '?token=' . urlencode($token) . '&expiry=' . $expiry_time;
$host = $_SERVER['HTTP_HOST']; // This will give you the host like 'linksehat.dev' or 'linksehat.com'
$base_url = "https://m.linksehat.dev/";
// Check if the host contains '.dev'
if (strpos($host, '.com') !== false) {
$base_url = "https://m.linksehat.com/";
}
$item->link_download = $base_url.$path;
return $item;
});
$apotekIds = $results->pluck(value: 'nIDApotek')->unique()->filter();
$organizations = DB::connection('mysql')->table('organizations')
->whereIn('id', $apotekIds)