|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Illuminate\Support\Facades\Schema; |
|
4
|
|
|
use Illuminate\Database\Schema\Blueprint; |
|
5
|
|
|
use Illuminate\Database\Migrations\Migration; |
|
6
|
|
|
|
|
7
|
|
|
class CreateRolesTable extends Migration |
|
|
|
|
|
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* Run the migrations. |
|
11
|
|
|
* |
|
12
|
|
|
* @return void |
|
13
|
|
|
*/ |
|
14
|
|
|
public function up() |
|
15
|
|
|
{ |
|
16
|
|
|
Schema::create(config('roleManager.rolesTable'), function (Blueprint $table) { |
|
|
|
|
|
|
17
|
|
|
$table->increments('id'); |
|
18
|
|
|
$table->char('name', 255)->unique(); |
|
19
|
|
|
$table->text('description')->nullable(); |
|
20
|
|
|
$table->timestamps(); |
|
21
|
|
|
}); |
|
22
|
|
|
Schema::create( |
|
|
|
|
|
|
23
|
|
|
'permissions_roles', |
|
24
|
|
View Code Duplication |
function (Blueprint $table) { |
|
|
|
|
|
|
25
|
|
|
$table->increments('id'); |
|
26
|
|
|
$table->integer('roles_id')->unsigned(); |
|
27
|
|
|
$table->integer('permissions_id')->unsigned(); |
|
28
|
|
|
$table->foreign('roles_id') |
|
29
|
|
|
->references('id') |
|
30
|
|
|
->on(config('roleManager.rolesTable')) |
|
31
|
|
|
->onDelete('cascade'); |
|
32
|
|
|
$table->foreign('permissions_id') |
|
33
|
|
|
->references('id') |
|
34
|
|
|
->on(config('roleManager.permissionsTable')) |
|
35
|
|
|
->onDelete('cascade'); |
|
36
|
|
|
} |
|
37
|
|
|
); |
|
38
|
|
|
|
|
39
|
|
|
Schema::create( |
|
|
|
|
|
|
40
|
|
|
'roles_user', |
|
41
|
|
View Code Duplication |
function (Blueprint $table) { |
|
|
|
|
|
|
42
|
|
|
$table->increments('id'); |
|
43
|
|
|
$table->integer('user_id')->unsigned(); |
|
44
|
|
|
$table->integer('roles_id')->unsigned(); |
|
45
|
|
|
$table->foreign('roles_id') |
|
46
|
|
|
->references('id') |
|
47
|
|
|
->on(config('roleManager.rolesTable')) |
|
48
|
|
|
->onDelete('cascade'); |
|
49
|
|
|
$table->foreign('user_id') |
|
50
|
|
|
->references('id')->on('users') |
|
51
|
|
|
->onDelete('cascade'); |
|
52
|
|
|
} |
|
53
|
|
|
); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* Reverse the migrations. |
|
58
|
|
|
* |
|
59
|
|
|
* @return void |
|
60
|
|
|
*/ |
|
61
|
|
|
public function down() |
|
62
|
|
|
{ |
|
63
|
|
|
Schema::dropIfExists('roles_user'); |
|
64
|
|
|
Schema::dropIfExists('permissions_roles'); |
|
65
|
|
|
Schema::dropIfExists(config('roleManager.rolesTable')); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
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.