51 lines
1.4 KiB
PHP
51 lines
1.4 KiB
PHP
|
<?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
|
||
|
],
|
||
|
]);
|
||
|
}
|
||
|
}
|