|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Illuminate\Database\Migrations\Migration; |
|
4
|
|
|
use Illuminate\Database\Schema\Blueprint; |
|
5
|
|
|
use Illuminate\Support\Facades\Schema; |
|
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
class CreateTranslationsTable extends Migration |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* Run the migrations. |
|
11
|
|
|
* |
|
12
|
|
|
* @return void |
|
13
|
|
|
*/ |
|
14
|
|
|
public function up() |
|
15
|
|
|
{ |
|
16
|
|
|
if (!Schema::hasTable('translations')) { |
|
17
|
|
|
Schema::create( |
|
18
|
|
|
'translations', function (Blueprint $table) { |
|
19
|
|
|
$table->increments('id'); |
|
20
|
|
|
$table->string('locale', 10); |
|
21
|
|
|
$table->string('namespace')->default('*'); |
|
22
|
|
|
$table->string('group'); |
|
23
|
|
|
$table->string('item'); |
|
24
|
|
|
$table->text('text'); |
|
25
|
|
|
$table->boolean('unstable')->default(false); |
|
26
|
|
|
$table->boolean('locked')->default(false); |
|
27
|
|
|
|
|
28
|
|
|
$table->unique(['locale', 'namespace', 'group', 'item']); |
|
29
|
|
|
|
|
30
|
|
|
$table->timestamps(); |
|
31
|
|
|
$table->softDeletes(); |
|
32
|
|
|
|
|
33
|
|
|
// @todo Tava no CMS |
|
34
|
|
|
// $table->increments('id'); |
|
35
|
|
|
// $table->integer('entity_id'); |
|
36
|
|
|
// $table->string('entity_type'); |
|
37
|
|
|
// $table->text('entity_data')->nullable(); |
|
38
|
|
|
// $table->nullableTimestamps(); |
|
39
|
|
|
// $table->string('language')->nullable(); |
|
40
|
|
|
} |
|
41
|
|
|
); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
try { |
|
45
|
|
|
if (!Schema::hasTable('model_translations')) { |
|
46
|
|
|
Schema::create( |
|
47
|
|
|
'model_translations', function (Blueprint $table) { |
|
48
|
|
|
$table->increments('id'); |
|
49
|
|
|
|
|
50
|
|
|
$table->string('entity_id'); |
|
51
|
|
|
$table->string('entity_type'); |
|
52
|
|
|
$table->string('entity_data')->nullable(); |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
$table->string('language_code'); |
|
56
|
|
|
$table->string('country_code')->nullable(); |
|
57
|
|
|
|
|
58
|
|
|
|
|
59
|
|
|
$table->foreign('language_code')->references('code')->on('languages'); |
|
60
|
|
|
$table->foreign('country_code')->references('code')->on('countries'); |
|
61
|
|
|
|
|
62
|
|
|
$table->unique(['entity_id', 'entity_type', 'language_code', 'country_code'], 'translation_unique'); |
|
63
|
|
|
// $table->primary(['entity_id', 'entity_type', 'language_code', 'country_code']); @todo |
|
64
|
|
|
|
|
65
|
|
|
$table->timestamps(); |
|
66
|
|
|
} |
|
67
|
|
|
); |
|
68
|
|
|
} |
|
69
|
|
|
//code... |
|
70
|
|
|
} catch (\Throwable $th) { |
|
71
|
|
|
//throw $th; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Reverse the migrations. |
|
77
|
|
|
* |
|
78
|
|
|
* @return void |
|
79
|
|
|
*/ |
|
80
|
|
|
public function down() |
|
81
|
|
|
{ |
|
82
|
|
|
Schema::dropIfExists('model_translations'); |
|
83
|
|
|
Schema::dropIfExists('translations'); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
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: