|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
use Illuminate\Database\Migrations\Migration; |
|
5
|
|
|
use Illuminate\Database\Schema\Blueprint; |
|
6
|
|
|
use Illuminate\Support\Facades\Schema; |
|
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
class CreateSitecTranslationsTable extends Migration |
|
9
|
|
|
{ |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Run the migrations. |
|
13
|
|
|
* |
|
14
|
|
|
* @return void |
|
15
|
|
|
*/ |
|
16
|
|
|
public function up() |
|
17
|
|
|
{ |
|
18
|
|
|
// if (!Schema::hasColumn('flights', 'departure_time')) { |
|
19
|
|
|
// $table->timestamp('departure_time'); |
|
20
|
|
|
// } |
|
21
|
|
|
if (!Schema::hasTable('countries')) { |
|
22
|
|
|
Schema::create( |
|
23
|
|
|
'countries', function (Blueprint $table) { |
|
24
|
|
|
$table->string('code')->unique(); |
|
25
|
|
|
$table->primary('code'); |
|
26
|
|
|
$table->string('name', 255); |
|
27
|
|
|
|
|
28
|
|
|
$table->timestamps(); |
|
29
|
|
|
$table->softDeletes(); |
|
30
|
|
|
} |
|
31
|
|
|
); |
|
32
|
|
|
} |
|
33
|
|
|
if (!Schema::hasTable('languages')) { |
|
34
|
|
|
Schema::create( |
|
35
|
|
|
'languages', function (Blueprint $table) { |
|
36
|
|
|
$table->engine = 'InnoDB'; |
|
37
|
|
|
$table->string('code')->unique(); |
|
38
|
|
|
$table->primary('code'); |
|
39
|
|
|
|
|
40
|
|
|
$table->integer('position')->nullable(); |
|
41
|
|
|
$table->string('name', 255); |
|
42
|
|
|
$table->boolean('is_default')->default(false); |
|
43
|
|
|
|
|
44
|
|
|
$table->timestamps(); |
|
45
|
|
|
$table->softDeletes(); |
|
46
|
|
|
} |
|
47
|
|
|
); |
|
48
|
|
|
} |
|
49
|
|
|
if (!Schema::hasTable('locales')) { |
|
50
|
|
|
Schema::create( |
|
51
|
|
|
'locales', function (Blueprint $table) { |
|
52
|
|
|
$table->string('language_code'); |
|
53
|
|
|
$table->string('country_code')->nullable(); |
|
54
|
|
|
|
|
55
|
|
|
$table->primary(['language_code','country_code']); |
|
56
|
|
|
|
|
57
|
|
|
$table->foreign('language_code')->references('code')->on('languages'); |
|
58
|
|
|
$table->foreign('country_code')->references('code')->on('countries'); |
|
59
|
|
|
|
|
60
|
|
|
$table->timestamps(); |
|
61
|
|
|
$table->softDeletes(); |
|
62
|
|
|
} |
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
// Schema::create('translations', function (Blueprint $table) { |
|
67
|
|
|
// $table->increments('id'); |
|
68
|
|
|
// $table->timestamps(); |
|
69
|
|
|
// $table->integer('locale_id')->unsigned(); |
|
70
|
|
|
// $table->integer('translation_id')->unsigned()->nullable(); |
|
71
|
|
|
// $table->text('translation'); |
|
72
|
|
|
|
|
73
|
|
|
// $table->foreign('locale_id')->references('id')->on('locales') |
|
74
|
|
|
// ->onUpdate('restrict') |
|
75
|
|
|
// ->onDelete('cascade'); |
|
76
|
|
|
|
|
77
|
|
|
// $table->foreign('translation_id')->references('id')->on('translations') |
|
78
|
|
|
// ->onUpdate('restrict') |
|
79
|
|
|
// ->onDelete('cascade'); |
|
80
|
|
|
// }); |
|
81
|
|
|
|
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Reverse the migrations. |
|
86
|
|
|
* |
|
87
|
|
|
* @return void |
|
88
|
|
|
*/ |
|
89
|
|
|
public function down() |
|
90
|
|
|
{ |
|
91
|
|
|
Schema::dropIfExists('locations'); |
|
92
|
|
|
Schema::dropIfExists('languages'); |
|
93
|
|
|
Schema::dropIfExists('locales'); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: