1
I’m doing a Seed from a Json file, I can read and populate the data, but at the time of linking the relationship between Dealership and Brands I can’t. How would I do that?
With the $filename = $file['filename'];
= Brand name
private function fillDealerships(array $files)
{
foreach ($files as $file) {
$data = $this->getFileContent($file);
foreach ($data as $item) {
$slug = isset($item['u']) ? Str::slug($item['u']) : $file['filename'];
$filename = $file['filename'];
/* @var $dealership Dealership */
$dealership = Dealership::query()->updateOrCreate([
'slug' => $slug,
], [
'name' => $item['n'] ?? $slug,
]);
// Brands()
if (isset($filename)) {
$dealership->brands();
}
$this->fillDealershipStore($dealership, $relation = null, $item);
}
}
}
In this section, I need to do the Sync of when I run the method it takes the first item, link with the mark and dps saves and rotate another seeing the loop...
// Brands()
if (isset($filename)) {
$dealership->brands();
}
- Structure of the Json
{
"suzuki": [
{
"n": "MOTO MAIS",
"u": "moto-mais",
"e": {
"l": "Av. Oswaldo Da Silva",
"n": "710",
"m": "",
"b": "Conjunto Habitacional Ana Jacinta",
"u": "19064070",
"c": {
"i": "9286",
"n": "Presidente Prudente"
},
"s": {
"i": "26",
"n": "Sao Paulo"
},
"r": "https:\/\/goo.gl\/maps\/aYoJgneRsTo",
"g": [
"-22.1505632",
"-51.4526682"
]
},
"c": {
"t": {
"c": {
"n": "(18) 3901-1911",
"l": "1839011911"
}
}
},
"r": {},
"g": null,
"t": "concessionaria-autorizada"
},
{
"n": "CLEIDSON MOTOS",
"u": "cleidson-motos",
"e": {
"l": "Av. Buriti Grande",
"n": "458",
"m": "",
"b": "Centro",
"u": "63.210-000",
"c": {
"i": "1469",
"n": "Mauriti"
},
"s": {
"i": "6",
"n": "Ceara"
},
"g": [
"-7.3873403",
"-38.7798318"
]
},
"c": {
"s": "https:\/\/suzukimotos.com.br",
"w": {
"n": "(88) 99682-7914",
"l": "88996827914"
},
"t": {
"c": {
"n": "(88) 3552-2114",
"l": "8835522114"
}
}
},
"r": {},
"g": null,
"t": "concessionaria-autorizada"
},
}
Put an example of JSON as well to make it easier to analyze and help you...
– Lodi
All right, I’ll insert
– Romulo Sousa