1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Dimsav\Translatable\Test\Model\City; |
4
|
|
|
use Dimsav\Translatable\Test\Model\CityTranslation; |
5
|
|
|
use Dimsav\Translatable\Test\Model\Country; |
6
|
|
|
use Dimsav\Translatable\Test\Model\CountryTranslation; |
7
|
|
|
use Illuminate\Database\Migrations\Migration; |
8
|
|
|
|
9
|
|
|
class AddSeeds extends Migration |
|
|
|
|
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Run the migrations. |
13
|
|
|
*/ |
14
|
|
|
public function up() |
15
|
|
|
{ |
16
|
|
|
$countries = [ |
17
|
|
|
['id' => 1, 'code' => 'gr'], |
18
|
|
|
['id' => 2, 'code' => 'fr'], |
19
|
|
|
['id' => 3, 'code' => 'en'], |
20
|
|
|
['id' => 4, 'code' => 'de'], |
21
|
|
|
]; |
22
|
|
|
|
23
|
|
|
$this->createCountries($countries); |
24
|
|
|
|
25
|
|
|
$countryTranslations = [ |
26
|
|
|
['country_id' => 1, 'locale' => 'el', 'name' => 'Ελλάδα'], |
27
|
|
|
['country_id' => 1, 'locale' => 'fr', 'name' => 'Grèce'], |
28
|
|
|
['country_id' => 1, 'locale' => 'en', 'name' => 'Greece'], |
29
|
|
|
['country_id' => 1, 'locale' => 'de', 'name' => 'Griechenland'], |
30
|
|
|
['country_id' => 2, 'locale' => 'en', 'name' => 'France'], |
31
|
|
|
]; |
32
|
|
|
|
33
|
|
|
$this->createCountryTranslations($countryTranslations); |
34
|
|
|
|
35
|
|
|
$cities = [ |
36
|
|
|
['id' => 1, 'country_id' => 1], |
37
|
|
|
]; |
38
|
|
|
|
39
|
|
|
$this->createCities($cities); |
40
|
|
|
|
41
|
|
|
$cityTranslations = [ |
42
|
|
|
['city_id' => 1, 'locale' => 'el', 'name' => 'Αθήνα'], |
43
|
|
|
['city_id' => 1, 'locale' => 'fr', 'name' => 'Athènes'], |
44
|
|
|
['city_id' => 1, 'locale' => 'en', 'name' => 'Athens'], |
45
|
|
|
['city_id' => 1, 'locale' => 'de', 'name' => 'Athen'], |
46
|
|
|
]; |
47
|
|
|
|
48
|
|
|
$this->createCityTranslations($cityTranslations); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
private function createCountries($countries) |
52
|
|
|
{ |
53
|
|
|
foreach ($countries as $data) { |
54
|
|
|
$country = new Country(); |
55
|
|
|
$country->id = $data['id']; |
|
|
|
|
56
|
|
|
$country->code = $data['code']; |
|
|
|
|
57
|
|
|
$country->save(); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
View Code Duplication |
private function createCountryTranslations($translations) |
|
|
|
|
62
|
|
|
{ |
63
|
|
|
foreach ($translations as $data) { |
64
|
|
|
$translation = new CountryTranslation(); |
65
|
|
|
$translation->country_id = $data['country_id']; |
|
|
|
|
66
|
|
|
$translation->locale = $data['locale']; |
|
|
|
|
67
|
|
|
$translation->name = $data['name']; |
|
|
|
|
68
|
|
|
$translation->save(); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
private function createCities($cities) |
73
|
|
|
{ |
74
|
|
|
foreach ($cities as $data) { |
75
|
|
|
$city = new City(); |
76
|
|
|
$city->id = $data['id']; |
|
|
|
|
77
|
|
|
$city->country_id = $data['country_id']; |
|
|
|
|
78
|
|
|
$city->save(); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
82
|
|
View Code Duplication |
private function createCityTranslations($translations) |
|
|
|
|
83
|
|
|
{ |
84
|
|
|
foreach ($translations as $data) { |
85
|
|
|
$translation = new CityTranslation(); |
86
|
|
|
$translation->city_id = $data['city_id']; |
|
|
|
|
87
|
|
|
$translation->locale = $data['locale']; |
|
|
|
|
88
|
|
|
$translation->name = $data['name']; |
|
|
|
|
89
|
|
|
$translation->save(); |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Reverse the migrations. |
95
|
|
|
*/ |
96
|
|
|
public function down() |
97
|
|
|
{ |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.