fwartner's avatar

Zero Padding from JSON

Hey everyone! I´m having problems while trying to using an JSON-Export file for my importer.

My json looks like this:

{
    "id": 16,
    "waggon_number": 2016,
    "short_train_number": 2016
  },
  {
    "id": 17,
    "waggon_number": 2017,
    "short_train_number": 2017
  },
  {
    "id": 18,
    "waggon_number": 2018,
    "short_train_number": 2018
  },
  {
    "id": 19,
    "waggon_number": 2019,
    "short_train_number": 2019
  },
  {
    "id": 20,
    "waggon_number": 2020,
    "short_train_number": 2020
  },
  {
    "id": 21,
    "waggon_number": 2021,
    "short_train_number": 2021
  },
  {
    "id": 22,
    "waggon_number": 2022,
    "short_train_number": 2022
  },
  {
    "id": 23,
    "waggon_number": 2023,
    "short_train_number": 2023
  },

My import-code looks like this:

$json = file_get_contents(storage_path('exports/train_mapping.json'));
        $collected = json_decode($json);

        foreach ($collected as $item) {
            $created = TrainMapping::create([
                'waggon_number' => $item->waggon_number,
                'short_train_number' => $item->short_train_number
            ]);
        }

Eloquent doesn´t allow me to create any new objects, when i have some special values..

How can i solve this?

0 likes
1 reply
psteenbergen's avatar

What kind of special values do you mean? I assume that the JSON is an array?

What kind of error are you getting now?

Please or to participate in this conversation.