75 lines
2.3 KiB
PHP
75 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Models\Role;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
class RoleSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*/
|
|
public function run(): void
|
|
{
|
|
// Create roles
|
|
$adminRole = Role::create([
|
|
'name' => 'Admin',
|
|
'slug' => 'admin',
|
|
'description' => 'Full access to all features and settings',
|
|
]);
|
|
|
|
$moderatorRole = Role::create([
|
|
'name' => 'Moderator',
|
|
'slug' => 'moderator',
|
|
'description' => 'Can approve/reject products and delete comments',
|
|
]);
|
|
|
|
$userRole = Role::create([
|
|
'name' => 'User',
|
|
'slug' => 'user',
|
|
'description' => 'Can submit products, upvote, and comment',
|
|
]);
|
|
|
|
// Create test users
|
|
$admin = User::create([
|
|
'name' => 'Admin User',
|
|
'email' => 'admin@example.com',
|
|
'password' => Hash::make('password'),
|
|
'bio' => 'Administrator of the platform',
|
|
'email_verified_at' => now(),
|
|
]);
|
|
$admin->roles()->attach($adminRole);
|
|
|
|
$moderator = User::create([
|
|
'name' => 'Moderator User',
|
|
'email' => 'moderator@example.com',
|
|
'password' => Hash::make('password'),
|
|
'bio' => 'Content moderator',
|
|
'email_verified_at' => now(),
|
|
]);
|
|
$moderator->roles()->attach($moderatorRole);
|
|
|
|
$regularUser = User::create([
|
|
'name' => 'Regular User',
|
|
'email' => 'user@example.com',
|
|
'password' => Hash::make('password'),
|
|
'bio' => 'Regular platform user',
|
|
'website' => 'https://example.com',
|
|
'twitter' => 'example',
|
|
'github' => 'example',
|
|
'linkedin' => 'example',
|
|
'email_verified_at' => now(),
|
|
]);
|
|
$regularUser->roles()->attach($userRole);
|
|
|
|
$this->command->info('Roles and test users created successfully!');
|
|
$this->command->info('Admin: admin@example.com / password');
|
|
$this->command->info('Moderator: moderator@example.com / password');
|
|
$this->command->info('User: user@example.com / password');
|
|
}
|
|
}
|