college-courses/database/seeders/UserSeeder.php

51 lines
1.4 KiB
PHP
Raw Permalink Normal View History

2024-10-15 10:15:40 +03:00
<?php
namespace Database\Seeders;
use App\Models\Role;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
class UserSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
//
if (Role::count() == 0) {
$roleSeeder = new RoleSeeder();
$roleSeeder->run();
}
$student_role = Role::query()->where('name', 'student')->first()->id;
$author_role = Role::query()->where('name', 'author')->first()->id;
$admin_role = Role::query()->where('name', 'admin')->first()->id;
DB::table('users')->insert([
[
'name' => 'user_student',
'password' => Hash::make('student_pass'),
'role_id' => $student_role
],
[
'name' => 'user_author',
'password' => Hash::make('author_pass'),
'role_id' => $author_role
],
[
'name' => 'user_admin',
'password' => Hash::make('admin_pass'),
'role_id' => $admin_role
],
[
'name' => 'superadmin',
'password' => Hash::make('superadmin'),
'role_id' => $admin_role
],
]);
}
}