1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Illuminate\Database\Schema\Blueprint; |
4
|
|
|
use Illuminate\Database\Migrations\Migration; |
5
|
|
|
|
6
|
|
|
use EmilMoe\Guardian\Support\Guardian; |
7
|
|
|
|
8
|
|
|
class CreateGuardianTables extends Migration |
|
|
|
|
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Run the migrations. |
12
|
|
|
* |
13
|
|
|
* @return void |
14
|
|
|
*/ |
15
|
|
|
public function up() |
16
|
|
|
{ |
17
|
|
|
Schema::create(config('guardian.table.permission'), function (Blueprint $table) { |
18
|
|
|
$table->increments('id'); |
19
|
|
|
$table->string('name')->unique(); |
20
|
|
|
$table->string('table'); |
21
|
|
|
$table->string('foreign_id_column'); |
22
|
|
|
$table->string('user_id_column'); |
23
|
|
|
$table->timestamps(); |
24
|
|
|
}); |
25
|
|
|
|
26
|
|
|
Schema::create(config('guardian.table.role'), function (Blueprint $table) { |
27
|
|
|
$table->increments('id'); |
28
|
|
|
$table->string('name'); |
29
|
|
|
$table->boolean('locked')->default(false); |
30
|
|
|
|
31
|
|
|
if (Guardian::hasClients()) |
32
|
|
|
$table->integer(Guardian::getClientColumn())->unsigned(); |
33
|
|
|
|
34
|
|
|
$table->timestamps(); |
35
|
|
|
|
36
|
|
|
if (Guardian::hasClients()) |
37
|
|
|
$table->foreign(Guardian::getClientColumn()) |
38
|
|
|
->references(Guardian::getClientKey()) |
39
|
|
|
->on(Guardian::getClientTable()) |
40
|
|
|
->onDelete('cascade'); |
41
|
|
|
}); |
42
|
|
|
|
43
|
|
|
Schema::create(config('guardian.table.role') .'_'. config('guardian.table.permission'), function (Blueprint $table) { |
44
|
|
|
$table->integer('permission_id')->unsigned(); |
45
|
|
|
$table->integer('role_id')->unsigned(); |
46
|
|
|
$table->timestamps(); |
47
|
|
|
$table->foreign('permission_id')->references('id')->on(config('guardian.table.permission'))->onDelete('cascade'); |
48
|
|
|
$table->foreign('role_id')->references('id')->on(config('guardian.table.role'))->onDelete('cascade'); |
49
|
|
|
}); |
50
|
|
|
|
51
|
|
|
Schema::create(Guardian::getUserTable() .'_'. config('guardian.table.role'), function (Blueprint $table) { |
52
|
|
|
$table->integer('user_id')->unsigned(); |
53
|
|
|
$table->integer('role_id')->unsigned(); |
54
|
|
|
$table->timestamps(); |
55
|
|
|
$table->foreign('user_id')->references(Guardian::getUserKey())->on(Guardian::getUserTable())->onDelete('cascade'); |
56
|
|
|
$table->foreign('role_id')->references('id')->on(config('guardian.table.role'))->onDelete('cascade'); |
57
|
|
|
}); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Reverse the migrations. |
62
|
|
|
* |
63
|
|
|
* @return void |
64
|
|
|
*/ |
65
|
|
|
public function down() |
66
|
|
|
{ |
67
|
|
|
Schema::drop(config('guardian.table.permission') .'_'. config('guardian.table.role')); |
68
|
|
|
Schema::drop(config('guardian.table.role')); |
69
|
|
|
Schema::drop(config('guardian.table.permission')); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|
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.