Add ranks and ACP user enhancements
This commit is contained in:
28
database/migrations/2026_01_05_020000_create_ranks_table.php
Normal file
28
database/migrations/2026_01_05_020000_create_ranks_table.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?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('ranks', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name')->unique();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('ranks');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,28 @@
|
||||
<?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::table('users', function (Blueprint $table) {
|
||||
$table->foreignId('rank_id')->nullable()->after('avatar_path')->constrained('ranks')->nullOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->dropConstrainedForeignId('rank_id');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,30 @@
|
||||
<?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::table('ranks', function (Blueprint $table) {
|
||||
$table->string('badge_type')->default('text')->after('name');
|
||||
$table->string('badge_text')->nullable()->after('badge_type');
|
||||
$table->string('badge_image_path')->nullable()->after('badge_text');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('ranks', function (Blueprint $table) {
|
||||
$table->dropColumn(['badge_type', 'badge_text', 'badge_image_path']);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -16,6 +16,7 @@ class DatabaseSeeder extends Seeder
|
||||
{
|
||||
$this->call([
|
||||
RoleSeeder::class,
|
||||
RankSeeder::class,
|
||||
UserSeeder::class,
|
||||
ForumSeeder::class,
|
||||
ThreadSeeder::class,
|
||||
|
||||
41
database/seeders/RankSeeder.php
Normal file
41
database/seeders/RankSeeder.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Rank;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class RankSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$member = Rank::firstOrCreate(
|
||||
['name' => 'Member'],
|
||||
['badge_type' => 'text', 'badge_text' => 'Member']
|
||||
);
|
||||
$operator = Rank::firstOrCreate(
|
||||
['name' => 'Operator'],
|
||||
['badge_type' => 'text', 'badge_text' => 'Operator']
|
||||
);
|
||||
$moderator = Rank::firstOrCreate(
|
||||
['name' => 'Moderator'],
|
||||
['badge_type' => 'text', 'badge_text' => 'Moderator']
|
||||
);
|
||||
|
||||
User::query()
|
||||
->whereNull('rank_id')
|
||||
->update(['rank_id' => $member->id]);
|
||||
|
||||
User::query()
|
||||
->whereHas('roles', fn ($query) => $query->where('name', 'ROLE_ADMIN'))
|
||||
->update(['rank_id' => $operator->id]);
|
||||
|
||||
User::query()
|
||||
->whereHas('roles', fn ($query) => $query->where('name', 'ROLE_MODERATOR'))
|
||||
->update(['rank_id' => $moderator->id]);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ namespace Database\Seeders;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Models\Rank;
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
|
||||
@@ -17,12 +18,15 @@ class UserSeeder extends Seeder
|
||||
{
|
||||
$adminRole = Role::where(column: 'name', operator: 'ROLE_ADMIN')->first();
|
||||
$userRole = Role::where(column: 'name', operator: 'ROLE_USER')->first();
|
||||
$operatorRank = Rank::where('name', 'Operator')->first();
|
||||
$memberRank = Rank::where('name', 'Member')->first();
|
||||
|
||||
$admin = User::updateOrCreate(
|
||||
attributes: ['email' => 'tracer@24unix.net'],
|
||||
values : [
|
||||
'name' => 'tracer',
|
||||
'name_canonical' => Str::lower('tracer'),
|
||||
'rank_id' => $operatorRank?->id ?? $memberRank?->id,
|
||||
'password' => Hash::make(value: 'password'),
|
||||
'email_verified_at' => now(),
|
||||
]
|
||||
@@ -33,6 +37,7 @@ class UserSeeder extends Seeder
|
||||
values : [
|
||||
'name' => 'Micha',
|
||||
'name_canonical' => Str::lower('Micha'),
|
||||
'rank_id' => $memberRank?->id,
|
||||
'password' => Hash::make(value: 'password'),
|
||||
'email_verified_at' => now(),
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user