So I am trying to seed data into my dB from an external api and not the default faker using the model factory in Laravel and I am stuck. Below is my code:
$factory->define(\App\Models\State::class, function(){
$client = new Client();
$stateQuery = $client->get('http://states-and-cities.com/api/v1/states');
$states = $stateQuery->getBody();
$states = json_decode($states, true);
foreach ($states as $state) {
return [
'name' => $state['name'],
];
}
});
So what's happening is that the return as expected is seeding only one record but I need it it to seed the whole records. How can I fix this?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire