Added roles and permissions in seeder

This commit is contained in:
dhanabalan
2025-04-23 14:47:11 +05:30
parent 26c3fee797
commit 488cfa3b61
4 changed files with 147 additions and 28 deletions

View File

@@ -3,6 +3,7 @@
namespace Database\Seeders;
use App\Models\User;
use Hash;
use Illuminate\Database\Seeder;
class UserSeeder extends Seeder
@@ -12,41 +13,101 @@ class UserSeeder extends Seeder
*/
public function run(): void
{
$user1 = User::create([
'name' => 'Admin',
'email' => 'admin@cripumps.com',
'password' => bcrypt('admin'),
]);
//updateOrCreate
$user1 = User::updateOrCreate(
// Unique identifier
['email' => 'admin@cripumps.com'],
// Data to update/create
[
'name' => 'Admin',
'password' => Hash::make('admin'),
'updated_at' => now(),
'created_at' => now()
]
);
// $user1 = User::firstOrCreate([
// 'name' => 'Admin',
// 'email' => 'admin@cripumps.com',
// 'password' => bcrypt('admin'),
// ]);
$user1->assignRole('Super Admin');
$user2 = User::create([
'name' => 'Jothi',
'email' => 'jothi@cripumps.com',
'password' => bcrypt('jothi@123'),
]);
$user2 = User::updateOrCreate(
// Unique identifier
['email' => 'jothi@cripumps.com'],
// Data to update/create
[
'name' => 'Jothi',
'password' => bcrypt('jothi@123'),
'updated_at' => now(),
'created_at' => now()
]
);
// $user2 = User::firstOrCreate([
// 'name' => 'Jothi',
// 'email' => 'jothi@cripumps.com',
// 'password' => bcrypt('jothi@123'),
// ]);
$user2->assignRole('Super Admin');
$user3 = User::create([
'name' => 'Dhana',
'email' => 'dhana@cripumps.com',
'password' => bcrypt('dhana@123'),
]);
$user3 = User::updateOrCreate(
// Unique identifier
['email' => 'dhana@cripumps.com'],
// Data to update/create
[
'name' => 'Dhana',
'password' => bcrypt('dhana@123'),
'updated_at' => now(),
'created_at' => now()
]
);
// $user3 = User::firstOrCreate([
// 'name' => 'Dhana',
// 'email' => 'dhana@cripumps.com',
// 'password' => bcrypt('dhana@123'),
// ]);
$user3->assignRole('Super Admin');
$user4 = User::create([
'name' => 'Ranjith',
'email' => 'ranjith@cripumps.com',
'password' => bcrypt('ranjith@123'),
]);
$user4 = User::updateOrCreate(
// Unique identifier
['email' => 'ranjith@cripumps.com'],
// Data to update/create
[
'name' => 'Ranjith',
'password' => bcrypt('ranjith@123'),
'updated_at' => now(),
'created_at' => now()
]
);
// $user4 = User::firstOrCreate([
// 'name' => 'Ranjith',
// 'email' => 'ranjith@cripumps.com',
// 'password' => bcrypt('ranjith@123'),
// ]);
$user4->assignRole('Super Admin');
$user5 = User::create([
'name' => 'Srimathi',
'email' => 'srimathi@cripumps.com',
'password' => bcrypt('srimathi@123'),
]);
$user5->assignRole('Super Admin');
$user5 = User::updateOrCreate(
// Unique identifier
['email' => 'srimathi@cripumps.com'],
User::factory()->count(5)->create();
// Data to update/create
[
'name' => 'Srimathi',
'password' => bcrypt('srimathi@123'),
'updated_at' => now(),
'created_at' => now()
]
);
// $user5 = User::firstOrCreate([
// 'name' => 'Srimathi',
// 'email' => 'srimathi@cripumps.com',
// 'password' => bcrypt('srimathi@123'),
// ]);
$user5->assignRole('Super Admin');
// User::factory()->count(5)->create();
}
}