Skip to content

Commit

Permalink
Merge branch '3.x' into 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ifox authored Nov 19, 2023
2 parents 3312342 + f10733d commit 15dd38f
Show file tree
Hide file tree
Showing 12 changed files with 199 additions and 160 deletions.
2 changes: 2 additions & 0 deletions config/twill.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@
'tags_table' => 'twill_tags',
'users_oauth_table' => 'twill_users_oauth',
'users_table' => 'twill_users',
'permissions_table' => 'permissions',
'roles_table' => 'roles',

/*
|--------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/content/1_docs/4_form-fields/06_multi-select.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ In this case that it can be implemented as follows:
- Create a Sectors [module](../3_modules/2_cli-generator.md)

```
php artisan twill:module sectors
php artisan twill:make:module sectors
```

- Create a migration for a pivot table.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Creating the page module

Now that we area ready with the initial setup of Laravel and Twill we can start building our CMS.
Now that we are ready with the initial setup of Laravel and Twill we can start building our CMS.

In Twill we use Modules. A module is a single "content type" and exists out of a few files:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@ class SupportPermission extends Migration
*/
public function up()
{
if (!Schema::hasTable('permissions')
$permissionsTableName = config('twill.permissions_table', 'permissions');
$rolesTableName = config('twill.roles_table', 'roles');

if (!Schema::hasTable($permissionsTableName)
&& !Schema::hasTable('groups')
&& !Schema::hasTable('roles')
&& !Schema::hasTable($rolesTableName)
&& !Schema::hasTable('permission_twill_user')
&& !Schema::hasTable('group_twill_user')
&& !Schema::hasTable('group_permission')
&& !Schema::hasTable('permission_role')
) {
Schema::create('permissions', function (Blueprint $table) {
Schema::create($permissionsTableName, function (Blueprint $table) {
createDefaultTableFields($table);
$table->string('name');
$table->string('display_name')->nullable();
Expand All @@ -40,14 +43,14 @@ public function up()
$table->boolean('is_everyone_group')->default(false);
});

Schema::create('roles', function (Blueprint $table) {
Schema::create($rolesTableName, function (Blueprint $table) {
createDefaultTableFields($table);
$table->string('name', 255)->nullable();
$table->boolean('in_everyone_group')->default(true);
$table->integer('position')->unsigned()->nullable();
});

Schema::create('permission_twill_user', function (Blueprint $table) {
Schema::create('permission_twill_user', function (Blueprint $table) use($permissionsTableName) {
$table->bigInteger('twill_user_id')->unsigned()->nullable();
$table->foreign('twill_user_id')
->references('id')
Expand All @@ -57,7 +60,7 @@ public function up()
$table->bigInteger('permission_id')->unsigned()->nullable();
$table->foreign('permission_id')
->references('id')
->on('permissions')
->on($permissionsTableName)
->onDelete('cascade');
});

Expand All @@ -77,11 +80,11 @@ public function up()
$table->integer('position')->unsigned()->nullable();
});

Schema::create('group_permission', function (Blueprint $table) {
Schema::create('group_permission', function (Blueprint $table) use($permissionsTableName) {
$table->bigInteger('permission_id')->unsigned()->nullable();
$table->foreign('permission_id')
->references('id')
->on('permissions')
->on($permissionsTableName)
->onDelete('cascade');

$table->bigInteger('group_id')->unsigned()->nullable();
Expand All @@ -91,17 +94,17 @@ public function up()
->onDelete('cascade');
});

Schema::create('permission_role', function (Blueprint $table) {
Schema::create('permission_role', function (Blueprint $table) use($permissionsTableName, $rolesTableName) {
$table->bigInteger('permission_id')->unsigned()->nullable();
$table->foreign('permission_id')
->references('id')
->on('permissions')
->on($permissionsTableName)
->onDelete('cascade');

$table->bigInteger('role_id')->unsigned()->nullable();
$table->foreign('role_id')
->references('id')
->on('roles')
->on($rolesTableName)
->onDelete('cascade');
});

Expand All @@ -118,13 +121,17 @@ public function up()
*/
public function down()
{
$permissionsTableName = config('twill.permissions_table', 'permissions');
$rolesTableName = config('twill.roles_table', 'roles');


Schema::dropIfExists('permission_twill_user');
Schema::dropIfExists('group_twill_user');
Schema::dropIfExists('group_permission');
Schema::dropIfExists('permission_role');
Schema::dropIfExists('permissions');
Schema::dropIfExists($permissionsTableName);
Schema::dropIfExists('groups');
Schema::dropIfExists('roles');
Schema::dropIfExists($rolesTableName);
}

private function seedBasicPermissions()
Expand Down
Loading

0 comments on commit 15dd38f

Please sign in to comment.