|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Illuminate\Database\Migrations\Migration; |
|
4
|
|
|
use Illuminate\Database\Schema\Blueprint; |
|
5
|
|
|
use Illuminate\Support\Facades\DB; |
|
6
|
|
|
use Illuminate\Support\Facades\Schema; |
|
7
|
|
|
|
|
8
|
|
|
class CreateWidgetsTable extends Migration |
|
|
|
|
|
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Run the migrations. |
|
12
|
|
|
* |
|
13
|
|
|
* @return void |
|
14
|
|
|
*/ |
|
15
|
|
|
public function up() |
|
16
|
|
|
{ |
|
17
|
|
|
DB::transaction(function () { |
|
18
|
|
|
Schema::create('widgets', function (Blueprint $table) { |
|
|
|
|
|
|
19
|
|
|
$table->increments('id'); |
|
20
|
|
|
$table->unsignedInteger('extension_id')->index(); |
|
21
|
|
|
$table->string('title')->index(); |
|
22
|
|
|
$table->string('position', 20)->index(); |
|
23
|
|
|
$table->string('template', 100)->default('default')->index(); |
|
24
|
|
|
$table->string('custom_template', 100)->nullable()->index(); |
|
25
|
|
|
$table->unsignedSmallInteger('order')->default(1); |
|
26
|
|
|
$table->boolean('published')->default(true)->index(); |
|
27
|
|
|
$table->boolean('show_title')->default(true)->index(); |
|
28
|
|
|
$table->boolean('authenticated')->default(false)->index(); |
|
29
|
|
|
$table->text('body')->nullable(); |
|
30
|
|
|
$table->text('parameters')->nullable(); |
|
31
|
|
|
$table->string('authorization', 20)->default('can'); |
|
32
|
|
|
$table->unsignedInteger('created_by')->nullable()->index(); |
|
33
|
|
|
$table->unsignedInteger('updated_by')->nullable()->index(); |
|
34
|
|
|
$table->timestamps(); |
|
35
|
|
|
|
|
36
|
|
|
$table->foreign('extension_id')->references('id')->on('extensions'); |
|
37
|
|
|
}); |
|
38
|
|
|
|
|
39
|
|
View Code Duplication |
Schema::create('widget_permission', function (Blueprint $table) { |
|
|
|
|
|
|
40
|
|
|
$table->unsignedInteger('widget_id')->index(); |
|
41
|
|
|
$table->unsignedInteger('permission_id')->index(); |
|
42
|
|
|
|
|
43
|
|
|
$table->foreign('widget_id')->references('id')->on('widgets')->onDelete('cascade'); |
|
44
|
|
|
$table->foreign('permission_id')->references('id')->on('permissions')->onDelete('cascade'); |
|
45
|
|
|
}); |
|
46
|
|
|
|
|
47
|
|
|
Schema::create('widget_menu', function (Blueprint $table) { |
|
|
|
|
|
|
48
|
|
|
$table->unsignedInteger('widget_id')->index(); |
|
49
|
|
|
$table->unsignedInteger('menu_id')->index(); |
|
50
|
|
|
|
|
51
|
|
|
$table->foreign('widget_id')->references('id')->on('widgets')->onDelete('cascade'); |
|
52
|
|
|
}); |
|
53
|
|
|
}); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Reverse the migrations. |
|
58
|
|
|
* |
|
59
|
|
|
* @return void |
|
60
|
|
|
*/ |
|
61
|
|
|
public function down() |
|
62
|
|
|
{ |
|
63
|
|
|
DB::transaction(function () { |
|
64
|
|
|
Schema::drop('widget_menu'); |
|
65
|
|
|
Schema::drop('widget_permission'); |
|
66
|
|
|
Schema::drop('widgets'); |
|
67
|
|
|
}); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
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.