1 | <?php |
||
6 | class CreatePermissionTables extends Migration |
||
|
|||
7 | { |
||
8 | /** |
||
9 | * Run the migrations. |
||
10 | * |
||
11 | * @return void |
||
12 | */ |
||
13 | public function up() |
||
14 | { |
||
15 | $config = config('laravel-permission.table_names'); |
||
16 | |||
17 | Schema::create($config['roles'], function (Blueprint $table) { |
||
18 | $table->increments('id'); |
||
19 | $table->string('name')->unique(); |
||
20 | $table->string('display_name')->nullable(); |
||
21 | $table->string('description')->nullable(); |
||
22 | $table->timestamps(); |
||
23 | }); |
||
24 | |||
25 | Schema::create($config['permissions'], function (Blueprint $table) { |
||
26 | $table->increments('id'); |
||
27 | $table->string('name')->unique(); |
||
28 | $table->string('display_name')->nullable(); |
||
29 | $table->string('description')->nullable(); |
||
30 | $table->timestamps(); |
||
31 | }); |
||
32 | |||
33 | Schema::create($config['user_has_permissions'], function (Blueprint $table) use ($config) { |
||
34 | $table->integer('user_id')->unsigned(); |
||
35 | $table->integer('permission_id')->unsigned(); |
||
36 | |||
37 | $table->foreign('user_id') |
||
38 | ->references('id') |
||
39 | ->on($config['users']) |
||
40 | ->onDelete('cascade'); |
||
41 | |||
42 | $table->foreign('permission_id') |
||
43 | ->references('id') |
||
44 | ->on($config['permissions']) |
||
45 | ->onDelete('cascade'); |
||
46 | |||
47 | $table->primary(['user_id', 'permission_id']); |
||
48 | }); |
||
49 | |||
50 | Schema::create($config['user_has_roles'], function (Blueprint $table) use ($config) { |
||
51 | $table->integer('role_id')->unsigned(); |
||
52 | $table->integer('user_id')->unsigned(); |
||
53 | |||
54 | $table->foreign('role_id') |
||
55 | ->references('id') |
||
56 | ->on($config['roles']) |
||
57 | ->onDelete('cascade'); |
||
58 | |||
59 | $table->foreign('user_id') |
||
60 | ->references('id') |
||
61 | ->on($config['users']) |
||
62 | ->onDelete('cascade'); |
||
63 | |||
64 | $table->primary(['role_id', 'user_id']); |
||
65 | }); |
||
66 | |||
67 | Schema::create($config['role_has_permissions'], function (Blueprint $table) use ($config) { |
||
68 | $table->integer('permission_id')->unsigned(); |
||
69 | $table->integer('role_id')->unsigned(); |
||
70 | |||
71 | $table->foreign('permission_id') |
||
72 | ->references('id') |
||
73 | ->on($config['permissions']) |
||
74 | ->onDelete('cascade'); |
||
75 | |||
76 | $table->foreign('role_id') |
||
77 | ->references('id') |
||
78 | ->on($config['roles']) |
||
79 | ->onDelete('cascade'); |
||
80 | |||
81 | $table->primary(['permission_id', 'role_id']); |
||
82 | }); |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * Reverse the migrations. |
||
87 | * |
||
88 | * @return void |
||
89 | */ |
||
90 | public function down() |
||
100 | } |
||
101 |
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.