Answer the question
In order to leave comments, you need to log in
Implementation of a drop-down list of country regions on the site?
I'm making a website on Laravel, I want to add a user's place of residence, so that there is a drop-down list of regions, create a migration table and add it to the MySQL database:
public function up()
{
Schema::create('regions', function(Blueprint $table)
{
$table->increments('id');
$table->string('name');
$table->string('slug')->unique();
$table->timestamps();
});
}
created RegionsTableSeeder.php with the following content:
public function run()
{
DB::table('regions')->delete();
Db::
array('name' => 'Autonomous Republic of Crimea', 'slug' => Slug::make('Autonomous Republic of Crimea'),
array('name' => 'Vinnitsa region', 'slug' => Slug:: make('Vinnytsia region'),
array('name' => 'Volyn region', 'slug' => Slug::make('Volyn region'),
array('name' => 'Dnepropetrovsk region', 'slug ' => Slug::make('Dnepropetrovsk region'),
array('name' => 'Donetsk region', 'slug' => Slug::make('Donetsk region'),
array('name' => ' Zhytomyr region', 'slug' => Slug::make('Zhytomyr region'),
array('name' => 'Transcarpathian region', 'slug' => Slug::make('Transcarpathian region'),
array('name' => 'Zaporozhye region', 'slug' => Slug::make('Zaporozhye region'),
array('name' => 'Ivano-Frankivsk region', 'slug' => Slug:: make('Ivano-Frankivsk region'),
array('name' => 'Kiev region', 'slug' => Slug::make('Kiev region'),
array('name' => 'Kiev', ' slug' => Slug::make('Kyiv'),
array('name' => 'Kirovohrad region', 'slug' => Slug::make('Kirovohrad region'),
array('name' => ' Lugansk region', 'slug' => Slug::make('Luhansk region'),
array('name' => 'Lviv region', 'slug' => Slug::make('Lviv region'),
array('name' => 'Mykolaiv region', 'slug' => Slug::make( 'Nikolaevkskaya area'),
array('name' => 'Odessa region', 'slug' => Slug::make('Odessa region'),
array('name' => 'Poltava region', 'slug' => Slug::make( 'Poltava region'),
array('name' => 'Rivne region', 'slug' => Slug::make('Rivne region'),
array('name' => 'Sevastopol', 'slug' => Slug::make('Sevastopol'),
array('name' => 'Sumy region', 'slug' => Slug::make('Sumy region'),
array('name' => 'Ternopil region', 'slug' => Slug::make('Ternopil region'),
array('name' => 'Kharkiv region', 'slug' => Slug::make('Kharkiv region'),
array('name' => 'Kherson region', 'slug' => Slug::make( 'Kherson region'),
array('name' => 'Khmelnytsky region', 'slug' => Slug::make('Khmelnytsky region'),
array('name' => 'Cherkasy region', 'slug' => Slug::make( 'Cherkasy region'),
array('name' => 'Chernihiv region', 'slug' => Slug::make('Chernihiv region'),
array('name' => 'Chernivtsi region', 'slug' = > Slug::make('Chernivtsi region'),
}
}
And what's next? I understand that you need to add these areas to MySQL, but I didn't quite understand how, through DatabaseSeeder.php? So it seems to be used for test data ?
Answer the question
In order to leave comments, you need to log in
You need to run migrations with seeding
php artisan migrate --seed
Well, you should use models, not DB::table
Create an \App\Region model in it add a setter setSlugAttribute($value) { $this->attributes['slug'] = \Slug::make($value); }
And then \App::Regoin::create(['name' => 'name1', 'slug' => 'slug1']);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question