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