"Deutsche Bahn" is a laravel package for timetables of german railway stations
Via Composer
$ composer require kayschima/deutsche-bahn
Publish the config file
$ php artisan vendor:publish --provider "Kayschima\DeutscheBahn\DeutscheBahnServiceProvider"
The usage of the package is quite simple:
- Get you API token at (https://developer.deutschebahn.com/store/).
- Fetch and install this package via Composer
- Set your API token in your .env file:
DEUTSCHE_BAHN_API_TOKEN=YOUR_API_TOKEN
You can use three different functions in this package:
use Kayschima\DeutscheBahn\Facades\DeutscheBahn;
$arrivals = DeutscheBahn::getArrivals('8000050', new DateTime('now'),true);
$departures = DeutscheBahn::getDepartures('8000050', new DateTime('now'), false);
$trainDetails = DeutscheBahn::getDetails('8000050hewrl7127871329172023440423023lhlhllklhlh50');
The first two functions expect
- an id a train station in Germany (in this example 'Bremen')
- a DateTime instance for date and time of the arrivals/departures
- a boolean (details of the train wanted of not)
If you want to know details about a specific train journey, enter the id of that train journey in the 'getDetails' function. You might get these ids by calling 'getArrivals' or 'getDepartures' before.
All functions return an array as a result. In later versions of the package we will also pass the results of the REST call on to the user.
Until then, an empty array is returned as the function result if an error occurs when calling the Deutsche Bahn api or the function has generally not determined any results.
This package also provides an artisan coommand to get the id of a certain railway station of Deutsche Bahn.
php artisan deutsche-bahn:railway-station
Just answer the question about the desired train station and a number of possible IDs will be displayed.
Please see the changelog for more information on what has changed recently.
$ composer test
Please see contributing.md for details and a todolist.
If you discover any security related issues, please email author email instead of using the issue tracker.
license. Please see the license file for more information.