Initial commit
This commit is contained in:
commit
c909d539bc
7178 files changed
+756624
No files matched your search
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Spatie\Permission\Models\Role;
|
||||
|
||||
class UserSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
// Ensure roles exist
|
||||
$roles = ['admin', 'teacher', 'student'];
|
||||
foreach ($roles as $role) {
|
||||
Role::firstOrCreate(
|
||||
['name' => $role, 'guard_name' => 'web']
|
||||
);
|
||||
}
|
||||
|
||||
// Create a default admin user
|
||||
$admin = User::firstOrCreate(
|
||||
['email' => 'admin@example.com'],
|
||||
[
|
||||
'name' => 'Admin User',
|
||||
'password' => Hash::make('password'), // change to something secure later
|
||||
]
|
||||
);
|
||||
|
||||
// Assign role
|
||||
if (!$admin->hasRole('admin')) {
|
||||
$admin->assignRole('admin');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user