Answer the question
In order to leave comments, you need to log in
Incorrect addition of data to the database through the seeder?
<?php
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
use App\Models\Location;
class DatabaseSeeder extends Seeder {
/**
* Run the database seeds.
*
* return void
*/
public function run()
{
Model::unguard();
// $this->call('UserTableSeeder');
$this->call('LocationsSeeder');
}
}
class LocationsSeeder extends Seeder {
public function run()
{
Location::create([
'name' => 'Vinnytsia region', 'parent_id' => '0', 'slug' => Slug::make('Vinnytsia region'),
'name' => 'Volyn region', 'parent_id ' => '0', 'slug' => Slug::make('Volyn region'),
'name' => 'Dnepropetrovsk region', 'parent_id' => '0', 'slug' => Slug ::make('Dnepropetrovsk region'),
'name' => 'Donetsk region', 'parent_id' => '0', 'slug' => Slug::make('Donetsk region'),
'name ' => 'Zhytomyr region', 'parent_id' => '0', 'slug' => Slug::make('Zhytomyr region'),
'name' => 'Transcarpathian region', 'parent_id' => '0', 'slug' => Slug::make('Transcarpathian region. '),
'name' => 'Zaporozhye region', 'parent_id' => '0', 'slug' => Slug::make('Zaporozhye region'),
'name' => 'Ivano-Frankivsk region', 'parent_id' => '0', 'slug' => Slug::make('Ivano-Frankivsk region'),
'name' => 'Kiev region', 'parent_id' => '0', 'slug ' => Slug::make('Kiev region'),
'name' => 'Kirovograd region', 'parent_id' => '0', 'slug' => Slug::make('Kirovograd region' ),
'name' => 'Luhansk region', 'parent_id' => '0', 'slug' => Slug::make('Luhansk region'),
'name' => 'Lviv region', 'parent_id' => '0', 'slug' => Slug::make( 'Lviv region'),
'name' => 'Mykolaiv region', 'parent_id' => '0', 'slug' => Slug::make('Mykolaiv region'),
'name' => 'Odessa region', 'parent_id ' => '0', 'slug' => Slug::make('Odessa region'),
'name' => 'Poltava region', 'parent_id' => '0', 'slug' => Slug ::make('Poltava region'),
'name' => 'Rivne region', 'parent_id' => '0', 'slug' => Slug::make('Rivne region'),
'name ' => 'Sumy region', 'parent_id' => '0', 'slug'=> Slug::make('Sumy region'),
'name' => 'Ternopil region', 'parent_id' => '0', 'slug' => Slug::make('Ternopil region') ,
slug' => Slug::make('Chernivtsi region'), 'name' => 'Chernivtsi region', 'parent_id' => '0', 'slug' => Slug::make('Chernivtsi region. '),
]);
}
}
When trying to add to the database, only the last line is added ( 'name' => 'Chernivtsi region', 'parent_id' => '0', 'slug' => Slug::make('Chernivtsi region'),)
Where I made a mistake
Answer the question
In order to leave comments, you need to log in
$items = [
['name' => 'Винницкая обл.', 'parent_id' => '0', 'slug' => Slug::make('Винницкая обл.')],
['name' => 'Волынская обл.', 'parent_id' => '0', 'slug' => Slug::make('Волынская обл.')],
['name' => 'Днепропетровская обл.', 'parent_id' => '0', 'slug' => Slug::make('Днепропетровская обл.')],
['name' => 'Донецкая обл.', 'parent_id' => '0', 'slug' => Slug::make('Донецкая обл.')],
['name' => 'Житомирская обл.', 'parent_id' => '0', 'slug' => Slug::make('Житомирская обл.')],
['name' => 'Закарпатская обл.', 'parent_id' => '0', 'slug' => Slug::make('Закарпатская обл.')],
['name' => 'Запорожская обл.', 'parent_id' => '0', 'slug' => Slug::make('Запорожская обл.')],
['name' => 'Ивано-Франковская обл.', 'parent_id' => '0', 'slug' => Slug::make('Ивано-Франковская обл.')],
['name' => 'Киевская обл.', 'parent_id' => '0', 'slug' => Slug::make('Киевская обл.')],
['name' => 'Кировоградская обл.', 'parent_id' => '0', 'slug' => Slug::make('Кировоградская обл.')],
['name' => 'Луганская обл.', 'parent_id' => '0', 'slug' => Slug::make('Луганская обл.')],
['name' => 'Львовская обл.', 'parent_id' => '0', 'slug' => Slug::make('Львовская обл.')],
['name' => 'Николаевская обл.', 'parent_id' => '0', 'slug' => Slug::make('Николаевская обл.')],
['name' => 'Одесская обл.', 'parent_id' => '0', 'slug' => Slug::make('Одесская обл.')],
['name' => 'Полтавская обл.', 'parent_id' => '0', 'slug' => Slug::make('Полтавская обл.')],
['name' => 'Ровненская обл.', 'parent_id' => '0', 'slug' => Slug::make('Ровненская обл.')],
['name' => 'Сумская обл.', 'parent_id' => '0', 'slug' => Slug::make('Сумская обл.')],
['name' => 'Тернопольская обл.', 'parent_id' => '0', 'slug' => Slug::make('Тернопольская обл.')],
['name' => 'Харьковская обл.', 'parent_id' => '0', 'slug' => Slug::make('Харьковская обл.')],
['name' => 'Херсонская обл.', 'parent_id' => '0', 'slug' => Slug::make('Херсонская обл.')],
['name' => 'Хмельницкая обл.', 'parent_id' => '0', 'slug' => Slug::make('Хмельницкая обл.')],
['name' => 'Черкасская обл.', 'parent_id' => '0', 'slug' => Slug::make('Черкасская обл.')],
['name' => 'Черниговская обл.', 'parent_id' => '0', 'slug' => Slug::make('Черниговская обл.')],
['name' => 'Черновицкая обл.', 'parent_id' => '0', 'slug' => Slug::make('Черновицкая обл.')],
];
foreach ($items as $item)
{
Location::create($item);
}
You create only one Location model, but you need to create multiple models. You have to do it like this, or something like this:
Location::create([
'name' => 'Винницкая обл.',
'parent_id' => '0',
'slug' => Slug::make('Винницкая обл.')
]);
Location::create([
'name' => 'Волынская обл.',
'parent_id' => '0',
'slug' => Slug::make('Волынская обл.')
]);
...
Location::create([
'name' => 'Черновицкая обл.',
'parent_id' => '0',
'slug' => Slug::make('Черновицкая обл.')
]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question