ozkanozcan / laravel-turkiye-kargo
Laravel 11-13 Turkish carriers: carrier registry, tracking links, tracking number detection, a unified shipment status model and a driver framework
Package info
github.com/ozkanozcan/laravel-turkiye-kargo
pkg:composer/ozkanozcan/laravel-turkiye-kargo
Requires
- php: ^8.2
- ext-json: *
- ext-mbstring: *
- illuminate/console: ^11.0|^12.0|^13.0
- illuminate/database: ^11.0|^12.0|^13.0
- illuminate/events: ^11.0|^12.0|^13.0
- illuminate/support: ^11.0|^12.0|^13.0
- illuminate/validation: ^11.0|^12.0|^13.0
Requires (Dev)
- orchestra/testbench: ^9.0|^10.0|^11.0
- phpunit/phpunit: ^10.0|^11.0|^12.0
Suggests
- ozkanozcan/laravel-turkiye: Turkish province and district names for sender and recipient addresses (optional, no dependency).
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-12-02 13:05:48 UTC
README
Turkish carriers for Laravel 11, 12, and 13: a carrier registry, public tracking links, tracking number detection, one shipment status model for every carrier and a driver framework with a fake driver.
A community package, not an official Laravel package.
This package is not affiliated with any carrier. Carrier names are used only to identify the services.
This is the PHP sibling of the Rust crate laravel-turkiye-kargo
(crates.io), which serves Laravel Rust. Both implement the same design and run the same test fixture
(fixtures/tracking.json), so they behave identically.
- Carrier registry: ten carriers with code, name, website and API driver status.
- Tracking links:
Kargo::trackingUrl($carrier, $number), only for pages verified on each carrier's own site. - Detection:
Kargo::detect($number)returns the carriers a number may belong to, with a confidence. Never a certainty. - Status model:
ShipmentStatus(English and Turkish labels),TrackingEvent,Tracking. - Drivers: the
CarrierDriverinterface (create shipment, label, track, cancel, quote, all optional) and aFakeDriver. No real carrier driver is included yet. - Laravel: config,
shipmentsandshipment_eventstables and Eloquent models, a status change event, the scheduledkargo:trackcommand and a validation rule.
Table of Contents
- Requirements
- Installation
- Configuration
- Supported carriers
- Usage
- Need a carrier integration?
- Data and legal
- Testing
- Türkçe
- Changelog
- Contributing
- License
Requirements
| Dependency | Version |
|---|---|
| PHP | ^8.2 (with ext-mbstring) |
| Laravel | 11.x / 12.x / 13.x |
No other package is required. For the province and district names of an address you may use
ozkanozcan/laravel-turkiye (optional suggestion, no dependency).
Installation
composer require ozkanozcan/laravel-turkiye-kargo php artisan migrate
The service provider and the Kargo facade alias are discovered automatically. The migrations create the shipments
and shipment_events tables. To publish them, the config or the translations:
php artisan vendor:publish --tag=kargo-config
php artisan vendor:publish --tag=kargo-migrations # then set load_migrations to false in config/kargo.php
php artisan vendor:publish --tag=kargo-lang
kargo:track is registered in the scheduler. You still need the usual schedule:run cron entry
(* * * * * php artisan schedule:run).
Configuration
| Variable | Default | Meaning |
|---|---|---|
KARGO_DEFAULT_CARRIER |
yurtici |
The carrier code used when a call does not name one. |
KARGO_SCHEDULE_ENABLED |
true |
Register the scheduled kargo:track task. |
KARGO_TRACK_CRON |
*/15 * * * * |
The cron expression of that task. |
KARGO_TRACK_LIMIT |
200 |
The most shipments one kargo:track run refreshes. |
KARGO_<CODE>_USERNAME, KARGO_<CODE>_PASSWORD |
unset | Credential placeholders per carrier (YURTICI, ARAS, MNG, PTT, SURAT, UPS_TR, HEPSIJET, KOLAYGELSIN, SENDEO, TRENDYOL_EXPRESS). Not used in 1.0.0: no driver reads them yet. They are redacted when dumped. |
The same variable names are used by the Rust crate. The table names (kargo.tables) and kargo.load_migrations are in
config/kargo.php.
Supported carriers
| Carrier | Code | Tracking link | API driver |
|---|---|---|---|
| Yurtiçi Kargo | yurtici |
yes | planned |
| Aras Kargo | aras |
yes | planned |
| MNG Kargo (DHL eCommerce Türkiye) | mng |
yes (page only) | planned |
| PTT Kargo | ptt |
yes (page only) | planned |
| Sürat Kargo | surat |
yes (page only) | planned |
| UPS Türkiye | ups_tr |
yes | planned |
| HepsiJET | hepsijet |
no | planned |
| Kolay Gelsin | kolaygelsin |
yes (page only) | planned |
| Sendeo | sendeo |
no | planned |
| Trendyol Express | trendyol_express |
yes | planned |
"Page only" means the carrier's tracking page takes the number through a form (often with a captcha), so the link opens
the page and the user types the number. "No" means no tracking page could be verified. Every link was checked on the
carrier's own site; see data/SOURCES.md for the date and what was seen.
Usage
Tracking links and detection
use OzkanOzcan\LaravelTurkiyeKargo\Carrier; use OzkanOzcan\LaravelTurkiyeKargo\KargoFacade as Kargo; // Spaces and case are normalized. Kargo::trackingUrl(Carrier::UpsTr, '1z 999 aa1 0123456784'); // "https://www.ups.com/track?loc=tr_TR&tracknum=1Z999AA10123456784" // A page that cannot be prefilled gives the page URL. Kargo::trackingUrl('mng', '123456789012'); // "https://www.dhlecommerce.com.tr/gonderitakip" // No verified page, or a bad number: null. Kargo::trackingUrl(Carrier::Hepsijet, '1234567890'); foreach (Kargo::detect('123456789012') as $candidate) { echo $candidate->carrier->displayName(), ' ', $candidate->confidence, "%\n"; // MNG 40, Yurtiçi 30, Aras 20, Sürat 15 }
Formats are mostly undocumented, so the rules are conservative heuristics: several candidates come back, none above
90%, and data/SOURCES.md marks which rules rest on a carrier's own form and which are only observed. When you know the
carrier, pass it instead of detecting.
Drivers and the fake driver
use OzkanOzcan\LaravelTurkiyeKargo\Carrier; use OzkanOzcan\LaravelTurkiyeKargo\Data\Address; use OzkanOzcan\LaravelTurkiyeKargo\Data\Parcel; use OzkanOzcan\LaravelTurkiyeKargo\Data\ShipmentRequest; use OzkanOzcan\LaravelTurkiyeKargo\Drivers\FakeDriver; $driver = new FakeDriver(Carrier::Yurtici); $request = (new ShipmentRequest( new Address('Shop', 'İstanbul', 'Kadıköy', 'Moda Cad. 1'), new Address('Ayşe Yılmaz', 'Ankara', 'Çankaya', 'Atatürk Blv. 2'), [Parcel::desi('2.5')], // 2.5 desi )) ->withCashOnDelivery('129.50') // 129.50 TRY, a string, never a float ->withReference('ORDER-1001'); $shipment = $driver->createShipment($request); $tracking = $driver->track($shipment->trackingNumber);
Money and measures are decimal strings (or integers); floats are not used anywhere, and no extension is needed. Write
your own carrier integration by extending Drivers\AbstractDriver: every method answers an "unsupported"
KargoException until you override it and report it in capabilities(). Addresses use province and district names as
Turkey writes them; an application that uses ozkanozcan/laravel-turkiye
may fill them from its tables (optional, there is no dependency).
Laravel
use OzkanOzcan\LaravelTurkiyeKargo\Carrier; use OzkanOzcan\LaravelTurkiyeKargo\Drivers\FakeDriver; use OzkanOzcan\LaravelTurkiyeKargo\KargoFacade as Kargo; use OzkanOzcan\LaravelTurkiyeKargo\Models\Shipment; // At boot (a service provider): give the service a driver per carrier. Kargo::extend(Carrier::Yurtici, new FakeDriver(Carrier::Yurtici)); $shipment = Shipment::create([ 'carrier' => 'yurtici', 'tracking_number' => '1234567890', 'reference' => 'ORDER-1001', ]); $shipment->trackingUrl(); // the public tracking page Kargo::track($shipment); // asks the driver, stores new events, updates the status $shipment->events; // the history, oldest first
kargo:track does this for every active shipment (a tracking number and a status that is not final), the ones tracked
longest ago first. It is scheduled with KARGO_TRACK_CRON; run it yourself with
php artisan kargo:track --limit=50 --carrier=yurtici. Without a driver for a shipment's carrier the shipment is
skipped.
When a refresh changes a status, ShipmentStatusChanged (shipmentId, carrier, trackingNumber, from, to) is
dispatched:
Event::listen(ShipmentStatusChanged::class, function (ShipmentStatusChanged $event) { if ($event->to === ShipmentStatus::Delivered) { /* ... */ } });
The validation rule checks a tracking number, optionally for one carrier:
use OzkanOzcan\LaravelTurkiyeKargo\Rules\TrackingNumber; $request->validate([ 'number' => ['required', TrackingNumber::withCarrierField('carrier')], // carrier from another field 'carrier' => ['nullable', 'string'], ]); 'number' => ['required', new TrackingNumber], // any plausible number 'number' => ['required', TrackingNumber::forCarrier(Carrier::Yurtici)], // a fixed carrier
new TrackingNumber accepts any plausible number (3 to 40 letters and digits once whitespace is removed);
forCarrier() and withCarrierField() also apply that carrier's own form limits. Messages are in English and Turkish.
Statuses
Created, PickedUp (Kabul edildi), InTransit (Transferde), AtBranch (Dağıtım şubesinde), OutForDelivery
(Dağıtımda), Delivered (Teslim edildi), DeliveryFailed (Teslim edilemedi), ReturnedToSender (İade), Cancelled
and Unknown, each with labelEn() and labelTr(). Delivered, ReturnedToSender and Cancelled are final.
A TrackingEvent keeps the carrier's own status text in rawStatus.
Need a carrier integration?
API drivers are added when a carrier provides documentation and sandbox access. If you are a carrier, or a company with API access to one, open a GitHub issue. Professional integration and support is available from the author: https://www.ozkanozcan.com (paid support).
Data and legal
No carrier documentation or WSDL files are included in this package; its types are written from scratch. Tracking
links and detection rules come from each carrier's own public website (see data/SOURCES.md). Carrier
names and websites are used only to identify the services; this package is not affiliated with, endorsed by or
sponsored by any carrier.
Testing
composer install vendor/bin/phpunit
The tracking and detection tests are driven by fixtures/tracking.json, the same file the Rust crate uses. The
integration tests use in-memory SQLite and FakeDriver; nothing touches a carrier. To change a link or a rule, update
data/SOURCES.md, the fixture and Carrier::trackingPage() together, and keep the Rust crate in step.
Türkçe
Resmi bir Laravel paketi değil, topluluk paketidir.
Laravel 11, 12 ve 13 için Türkiye kargo firmaları: firma kaydı, herkese açık takip bağlantıları, takip numarasından
firma tahmini, tüm firmalar için tek bir gönderi durum modeli ve sahte (fake) sürücülü bir sürücü altyapısı. Rust
kardeşi laravel-turkiye-kargo ile aynı tasarımı ve aynı test
verilerini kullanır.
Bu paket hiçbir kargo firmasıyla bağlantılı değildir. Firma adları yalnızca hizmetleri tanımlamak için kullanılır.
Kargo::trackingUrl($firma, $numara)yalnızca firmanın kendi sitesinde doğrulanmış takip sayfaları için bağlantı üretir. Numarayı yalnızca form (çoğu zaman captcha) ile alan sayfalarda sayfanın adresi döner.Kargo::detect($numara)numaranın hangi firmalara ait olabileceğini güven yüzdesiyle listeler; kesin sonuç iddia etmez. Firmayı biliyorsanız doğrudan verin.ShipmentStatusdurumları İngilizce ve Türkçe etiketlerle sunar: Kabul edildi, Transferde, Dağıtım şubesinde, Dağıtımda, Teslim edildi, Teslim edilemedi, İade.CarrierDriverile kendi firma entegrasyonunuzu yazabilirsiniz (gönderi oluşturma, etiket, takip, iptal, fiyat sorgusu; hepsi isteğe bağlı). Tutarlar ondalık metin (string) olarak tutulur, ondalık sayı (float) kullanılmaz.shipmentsveshipment_eventstabloları,ShipmentveShipmentEventmodelleri, durum değişince tetiklenenShipmentStatusChangedolayı, zamanlayıcıya kayıtlıkargo:trackkomutu ve takip numarası doğrulama kuralı (TrackingNumber) gelir.
composer require ozkanozcan/laravel-turkiye-kargo php artisan migrate
Kargo entegrasyonu mu lazım?
API sürücüleri, kargo firması dokümantasyon ve sandbox erişimi sağladığında eklenir. Kargo firmasıysanız ya da bir firmanın API erişimine sahip bir şirketseniz GitHub'da bir issue açın. Profesyonel entegrasyon ve destek yazardan alınabilir: https://www.ozkanozcan.com (ücretli destek).
Veri ve hukuk
Pakete hiçbir kargo firmasının dokümanı veya WSDL dosyası dahil değildir; tipler sıfırdan yazılmıştır. Bağlantılar ve
tahmin kuralları firmaların kendi herkese açık sitelerinden alınmıştır (bkz. data/SOURCES.md).
Changelog
See CHANGELOG.md for a history of changes.
Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature/my-feature - Commit your changes following Conventional Commits
- Push and open a Pull Request against
main
Carrier sites change. Before a release, open each page listed in data/SOURCES.md again, update that file, the
fixture and Carrier::trackingPage(), and run the tests of both packages. Please make sure all tests pass before
submitting a PR.
License
MIT © Özkan Özcan
See LICENSE for full details.