Support the ongoing development of Laravel.io →
Database Eloquent

Hello,

Ok, so I am trying to seed data into a table, below is what I have tried:

 $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'],
               ];
    }
});

This return only on state because well it's return. Is there some way I can do this?

Last updated 3 years ago.
0

why not just insert everything right in the seeder class, no need for a factory ?

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.