groups and roles

This commit is contained in:
DigitalInfinity committed 2026-06-02 15:46:00 +00:00
1 parent f82d3f59e0
commit 0b78ea4d03
21 files changed
+412 -27

No files matched your search

@@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('roles', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->string('name');
$table->string('title');
$table->string('description')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('roles');
}
};
@@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('groups', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->string('name');
$table->string('description')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('groups');
}
};
@@ -0,0 +1,31 @@
<?php
use App\Models\Group;
use App\Models\User;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('group_user', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->foreignIdFor(User::class);
$table->foreignIdFor(Group::class);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('group_user');
}
};
@@ -0,0 +1,31 @@
<?php
use App\Models\Role;
use App\Models\User;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('role_user', function (Blueprint $table) {
$table->id();
$table->timestamps();
$table->foreignIdFor(Role::class);
$table->foreignIdFor(User::class);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('role_user');
}
};
@@ -0,0 +1,44 @@
<?php
use App\Models\Role;
use App\Models\User;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
$ordermanager = Role::firstOrCreate(["name" => "ordermanager", 'title' => 'Ordermanager', 'description' => 'Verwaltet Bestellungen'])->save();
$users = User::all();
foreach($users as $user) {
if($user->ordermanager) $user->roles()->attach($ordermanager);
}
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('ordermanager');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->boolean("ordermanager")->default(false);
});
$users = User::all();
foreach($users as $user) {
if($user->hasRole("ordermanager")) {
$user->ordermanager = 1;
$user->save();
}
}
}
};