37 lines
921 B
PHP
37 lines
921 B
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Models\Post;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
|
use Illuminate\Database\Seeder;
|
|
|
|
class DatabaseSeeder extends Seeder
|
|
{
|
|
use WithoutModelEvents;
|
|
|
|
/**
|
|
* Seed the application's database.
|
|
*/
|
|
public function run(): void
|
|
{
|
|
// Создание администратора
|
|
User::create([
|
|
'name' => 'Admin User',
|
|
'email' => 'admin@example.com',
|
|
'password' => bcrypt('password'),
|
|
'role' => 'admin',
|
|
]);
|
|
|
|
// Создание обычных пользователей
|
|
$users = User::factory(5)->create(['role' => 'user']);
|
|
|
|
// Создание постов для каждого пользователя
|
|
foreach ($users as $user) {
|
|
Post::factory(3)->create(['user_id' => $user->id]);
|
|
}
|
|
}
|
|
|
|
}
|