@@ 7-53 (lines=47) @@ | ||
4 | use Illuminate\Database\Schema\Blueprint; |
|
5 | use Illuminate\Database\Migrations\Migration; |
|
6 | ||
7 | class CreateSpatieModelHasPermissionsTable extends Migration |
|
8 | { |
|
9 | /** |
|
10 | * Run the migrations. |
|
11 | * |
|
12 | * @return void |
|
13 | */ |
|
14 | public function up() |
|
15 | { |
|
16 | $tableNames = config('permission.table_names'); |
|
17 | $columnNames = config('permission.column_names'); |
|
18 | ||
19 | Schema::create($tableNames['model_has_permissions'], function (Blueprint $table) use ($tableNames, $columnNames) { |
|
20 | $table->unsignedBigInteger('permission_id'); |
|
21 | ||
22 | $table->string('model_type'); |
|
23 | $table->unsignedBigInteger($columnNames['model_morph_key']); |
|
24 | $table->index([$columnNames['model_morph_key'], 'model_type',]); |
|
25 | ||
26 | $table->foreign('permission_id') |
|
27 | ->references('id') |
|
28 | ->on($tableNames['permissions']) |
|
29 | ->onDelete('cascade'); |
|
30 | ||
31 | $table->primary( |
|
32 | ['permission_id', $columnNames['model_morph_key'], 'model_type'], |
|
33 | 'model_has_permissions_permission_model_type_primary' |
|
34 | ); |
|
35 | }); |
|
36 | ||
37 | app('cache') |
|
38 | ->store(config('permission.cache.store') != 'default' ? config('permission.cache.store') : null) |
|
39 | ->forget(config('permission.cache.key')); |
|
40 | } |
|
41 | ||
42 | /** |
|
43 | * Reverse the migrations. |
|
44 | * |
|
45 | * @return void |
|
46 | */ |
|
47 | public function down() |
|
48 | { |
|
49 | $tableNames = config('permission.table_names'); |
|
50 | ||
51 | Schema::drop($tableNames['model_has_permissions']); |
|
52 | } |
|
53 | } |
|
54 |
@@ 7-50 (lines=44) @@ | ||
4 | use Illuminate\Database\Schema\Blueprint; |
|
5 | use Illuminate\Database\Migrations\Migration; |
|
6 | ||
7 | class CreateSpatieModelHasRolesTable extends Migration |
|
8 | { |
|
9 | /** |
|
10 | * Run the migrations. |
|
11 | * |
|
12 | * @return void |
|
13 | */ |
|
14 | public function up() |
|
15 | { |
|
16 | $tableNames = config('permission.table_names'); |
|
17 | $columnNames = config('permission.column_names'); |
|
18 | ||
19 | Schema::create($tableNames['model_has_roles'], function (Blueprint $table) use ($tableNames, $columnNames) { |
|
20 | $table->unsignedBigInteger('role_id'); |
|
21 | $table->string('model_type'); |
|
22 | $table->unsignedBigInteger($columnNames['model_morph_key']); |
|
23 | $table->index([$columnNames['model_morph_key'], 'model_type',]); |
|
24 | $table->foreign('role_id') |
|
25 | ->references('id') |
|
26 | ->on($tableNames['roles']) |
|
27 | ->onDelete('cascade'); |
|
28 | $table->primary( |
|
29 | ['role_id', $columnNames['model_morph_key'], 'model_type'], |
|
30 | 'model_has_roles_role_model_type_primary' |
|
31 | ); |
|
32 | }); |
|
33 | ||
34 | app('cache') |
|
35 | ->store(config('permission.cache.store') != 'default' ? config('permission.cache.store') : null) |
|
36 | ->forget(config('permission.cache.key')); |
|
37 | } |
|
38 | ||
39 | /** |
|
40 | * Reverse the migrations. |
|
41 | * |
|
42 | * @return void |
|
43 | */ |
|
44 | public function down() |
|
45 | { |
|
46 | $tableNames = config('permission.table_names'); |
|
47 | ||
48 | Schema::drop($tableNames['model_has_roles']); |
|
49 | } |
|
50 | } |
|
51 |