PHP code example of denizgolbas / laravel-tcmb-gold
1. Go to this page and download the library: Download denizgolbas/laravel-tcmb-gold library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
denizgolbas / laravel-tcmb-gold example snippets
$rates = TcmbGold::all();
// XAU (24 Ayar) ve XAS (SAF/Has) altın fiyatlarını getirir
// Paket otomatik olarak 12:00, 14:00, 16:00 saatlerinde XML'i kontrol eder
// İlk bulduğu geçerli veriyi döner
$rates = TcmbGold::all();
// config/tcmb-gold.php
'cache_duration' => 120, // 2 saat (dakika cinsinden)
// Cache'i temizlemek için
Cache::forget('tcmb_gold_2025-12-09_12:00');
use DenizTezc\TcmbGold\Models\GoldRate;
$rates = TcmbGold::all();
foreach ($rates as $rate) {
GoldRate::updateOrCreate(
['code' => $rate['code'], 'date' => $rate['date']],
$rate
);
}
use DenizTezc\TcmbGold\Facades\TcmbGold;
// Bugünün tüm altın fiyatlarını al (XAU + XAS)
$rates = TcmbGold::all();
// Tüm altın türlerini listele
foreach ($rates as $gold) {
echo "{$gold['name']}: {$gold['buying']} TL\n";
}
// Output:
// 24 Ayar Altın: 5734.7 TL
// SAF (Has) Altın: 5763.52 TL
// SAF (Has) Altın (gram fiyatı)
$hasAltin = $rates->firstWhere('code', 'XAS');
echo "1 gram saf altın: {$hasAltin['buying']} TL";
// 24 Ayar Altın
$xau = $rates->firstWhere('code', 'XAU');
echo "24 ayar altın: {$xau['buying']} TL";
use Illuminate\Support\Carbon;
$date = Carbon::parse('2025-12-01');
$rates = TcmbGold::all($date);