LMS Этап 1 MVP - Laravel 13

 Базовая функциональность:
- Аутентификация (вход/выход/регистрация)
- Роли и разрешения (Administrator, Manager, Curator, Student)
- Панель управления (dashboard) для разных ролей

 База данных (23 миграции):
- users, organizations, groups, user_groups
- course_categories, courses, course_modules
- tests, questions, answers, question_matching_pairs
- test_attempts, test_responses
- course_requests, course_request_items, course_assignments
- scorm_data, user_course_progress, logs
- permission tables

 Модели (15 моделей с отношениями):
- User, Organization, Group
- CourseCategory, Course, CourseModule
- Test, Question, Answer, QuestionMatchingPair
- TestAttempt, TestResponse
- CourseRequest, CourseRequestItem, CourseAssignment
- ScormData, UserCourseProgress, Log

 Seeders:
- RoleSeeder (роли и разрешения)
- UserSeeder (тестовые пользователи)

 Контроллеры:
- LoginController, RegisterController, DashboardController

 Blade-шаблоны:
- layouts/app.blade.php
- auth/login.blade.php, auth/register.blade.php
- dashboard/admin.blade.php, dashboard/curator.blade.php, dashboard/student.blade.php

📦 Пакеты:
- Laravel 13 (dev-master)
- spatie/laravel-permission
- laravel/sanctum

🔧 Инфраструктура:
- Nginx конфигурация
- PHP 8.4-FPM
- MariaDB

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
mirivlad
2026-03-25 17:30:37 +08:00
co-authored by Qwen-Coder
commit 244c56df39
131 changed files with 13381 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
*.sqlite*
+44
View File
@@ -0,0 +1,44 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
*/
class UserFactory extends Factory
{
/**
* The current password being used by the factory.
*/
protected static ?string $password;
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'name' => fake()->name(),
'email' => fake()->unique()->safeEmail(),
'email_verified_at' => now(),
'password' => static::$password ??= Hash::make('password'),
'remember_token' => Str::random(10),
];
}
/**
* Indicate that the model's email address should be unverified.
*/
public function unverified(): static
{
return $this->state(fn (array $attributes) => [
'email_verified_at' => null,
]);
}
}
@@ -0,0 +1,40 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('organization_id')->nullable();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->string('phone')->nullable();
$table->string('avatar')->nullable();
$table->boolean('is_active')->default(true);
$table->rememberToken();
$table->timestamps();
$table->index('organization_id');
$table->index('is_active');
$table->index('email');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('users');
}
};
@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('password_reset_tokens', function (Blueprint $table) {
$table->string('email')->primary();
$table->string('token');
$table->timestamp('created_at')->nullable();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('password_reset_tokens');
}
};
@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('failed_jobs', function (Blueprint $table) {
$table->id();
$table->string('uuid')->unique();
$table->text('connection');
$table->text('queue');
$table->longText('payload');
$table->longText('exception');
$table->timestamp('failed_at')->useCurrent();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('failed_jobs');
}
};
@@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('personal_access_tokens', function (Blueprint $table) {
$table->id();
$table->morphs('tokenable');
$table->string('name');
$table->string('token', 64)->unique();
$table->text('abilities')->nullable();
$table->timestamp('last_used_at')->nullable();
$table->timestamp('expires_at')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('personal_access_tokens');
}
};
@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('organizations', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('inn')->nullable();
$table->string('kpp')->nullable();
$table->text('address')->nullable();
$table->string('phone')->nullable();
$table->string('email')->nullable();
$table->text('description')->nullable();
$table->boolean('is_active')->default(true);
$table->timestamps();
$table->index('is_active');
$table->index('created_at');
});
}
public function down(): void
{
Schema::dropIfExists('organizations');
}
};
@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('groups', function (Blueprint $table) {
$table->id();
$table->foreignId('organization_id')->constrained()->onDelete('cascade');
$table->string('name');
$table->text('description')->nullable();
$table->boolean('is_active')->default(true);
$table->timestamps();
$table->index('organization_id');
$table->index('is_active');
});
}
public function down(): void
{
Schema::dropIfExists('groups');
}
};
@@ -0,0 +1,26 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('user_groups', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->onDelete('cascade');
$table->foreignId('group_id')->constrained()->onDelete('cascade');
$table->timestamps();
$table->unique(['user_id', 'group_id']);
$table->index('group_id');
});
}
public function down(): void
{
Schema::dropIfExists('user_groups');
}
};
@@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('course_categories', function (Blueprint $table) {
$table->id();
$table->foreignId('parent_id')->nullable()->constrained('course_categories')->onDelete('set null');
$table->string('name');
$table->string('slug')->unique();
$table->text('description')->nullable();
$table->integer('sort_order')->default(0);
$table->boolean('is_active')->default(true);
$table->timestamps();
$table->index('parent_id');
$table->index('is_active');
$table->index('slug');
});
}
public function down(): void
{
Schema::dropIfExists('course_categories');
}
};
@@ -0,0 +1,42 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('courses', function (Blueprint $table) {
$table->id();
$table->foreignId('category_id')->nullable()->constrained('course_categories')->onDelete('set null');
$table->foreignId('created_by')->nullable()->constrained('users')->onDelete('set null');
$table->string('title');
$table->string('slug')->unique();
$table->text('description')->nullable();
$table->text('objectives')->nullable();
$table->string('thumbnail')->nullable();
$table->enum('type', ['standard', 'scorm', 'h5p'])->default('standard');
$table->string('scorm_package_path')->nullable();
$table->string('h5p_package_path')->nullable();
$table->integer('duration_minutes')->nullable();
$table->boolean('has_certificate')->default(false);
$table->integer('passing_score')->default(70);
$table->boolean('is_active')->default(true);
$table->timestamp('published_at')->nullable();
$table->timestamps();
$table->index('category_id');
$table->index('type');
$table->index('is_active');
$table->index('slug');
$table->index('created_at');
});
}
public function down(): void
{
Schema::dropIfExists('courses');
}
};
@@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('course_modules', function (Blueprint $table) {
$table->id();
$table->foreignId('course_id')->constrained()->onDelete('cascade');
$table->foreignId('parent_id')->nullable()->constrained('course_modules')->onDelete('cascade');
$table->string('title');
$table->text('content')->nullable();
$table->enum('type', ['lesson', 'test', 'scorm', 'h5p', 'assignment'])->default('lesson');
$table->integer('sort_order')->default(0);
$table->integer('duration_minutes')->nullable();
$table->boolean('is_required')->default(true);
$table->boolean('is_active')->default(true);
$table->timestamps();
$table->index('course_id');
$table->index('parent_id');
$table->index('type');
$table->index('sort_order');
});
}
public function down(): void
{
Schema::dropIfExists('course_modules');
}
};
@@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('tests', function (Blueprint $table) {
$table->id();
$table->foreignId('course_id')->constrained()->onDelete('cascade');
$table->foreignId('module_id')->nullable()->constrained('course_modules')->onDelete('cascade');
$table->string('title');
$table->text('description')->nullable();
$table->enum('type', ['probationary', 'final', 'intermediate'])->default('intermediate');
$table->integer('time_limit_minutes')->nullable();
$table->integer('passing_score')->default(70);
$table->integer('max_attempts')->default(3);
$table->boolean('shuffle_questions')->default(false);
$table->boolean('show_correct_answers')->default(true);
$table->boolean('is_active')->default(true);
$table->timestamps();
$table->index('course_id');
$table->index('module_id');
$table->index('type');
});
}
public function down(): void
{
Schema::dropIfExists('tests');
}
};
@@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('questions', function (Blueprint $table) {
$table->id();
$table->foreignId('test_id')->constrained()->onDelete('cascade');
$table->enum('type', ['single_choice', 'multiple_choice', 'input', 'matching'])->default('single_choice');
$table->text('question_text');
$table->text('explanation')->nullable();
$table->integer('score')->default(1);
$table->integer('sort_order')->default(0);
$table->boolean('is_required')->default(true);
$table->timestamps();
$table->index('test_id');
$table->index('type');
});
}
public function down(): void
{
Schema::dropIfExists('questions');
}
};
@@ -0,0 +1,27 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('answers', function (Blueprint $table) {
$table->id();
$table->foreignId('question_id')->constrained()->onDelete('cascade');
$table->string('answer_text');
$table->boolean('is_correct')->default(false);
$table->integer('sort_order')->default(0);
$table->timestamps();
$table->index('question_id');
});
}
public function down(): void
{
Schema::dropIfExists('answers');
}
};
@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('question_matching_pairs', function (Blueprint $table) {
$table->id();
$table->foreignId('question_id')->constrained()->onDelete('cascade');
$table->string('left_text');
$table->string('right_text');
$table->integer('match_score')->default(1);
$table->integer('sort_order')->default(0);
$table->timestamps();
$table->index('question_id');
});
}
public function down(): void
{
Schema::dropIfExists('question_matching_pairs');
}
};
@@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('test_attempts', function (Blueprint $table) {
$table->id();
$table->foreignId('test_id')->constrained()->onDelete('cascade');
$table->foreignId('user_id')->constrained()->onDelete('cascade');
$table->timestamp('started_at');
$table->timestamp('finished_at')->nullable();
$table->integer('score')->nullable();
$table->integer('correct_answers')->nullable();
$table->integer('total_questions')->nullable();
$table->boolean('passed')->nullable();
$table->text('feedback')->nullable();
$table->timestamps();
$table->index('test_id');
$table->index('user_id');
$table->index('started_at');
$table->index('passed');
});
}
public function down(): void
{
Schema::dropIfExists('test_attempts');
}
};
@@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('test_responses', function (Blueprint $table) {
$table->id();
$table->foreignId('attempt_id')->constrained('test_attempts')->onDelete('cascade');
$table->foreignId('question_id')->constrained()->onDelete('cascade');
$table->foreignId('answer_id')->nullable()->constrained()->onDelete('cascade');
$table->text('text_response')->nullable();
$table->json('matching_response')->nullable();
$table->boolean('is_correct')->nullable();
$table->integer('score')->default(0);
$table->timestamps();
$table->index('attempt_id');
$table->index('question_id');
});
}
public function down(): void
{
Schema::dropIfExists('test_responses');
}
};
@@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('course_requests', function (Blueprint $table) {
$table->id();
$table->foreignId('organization_id')->constrained()->onDelete('cascade');
$table->foreignId('requested_by_user_id')->constrained('users')->onDelete('cascade');
$table->foreignId('approved_by_user_id')->nullable()->constrained('users')->onDelete('set null');
$table->enum('status', ['pending', 'approved', 'rejected'])->default('pending');
$table->text('comment')->nullable();
$table->timestamp('approved_at')->nullable();
$table->timestamps();
$table->index('organization_id');
$table->index('status');
$table->index('created_at');
});
}
public function down(): void
{
Schema::dropIfExists('course_requests');
}
};
@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('course_request_items', function (Blueprint $table) {
$table->id();
$table->foreignId('request_id')->constrained('course_requests')->onDelete('cascade');
$table->foreignId('course_id')->constrained()->onDelete('cascade');
$table->foreignId('user_id')->nullable()->constrained()->onDelete('cascade');
$table->timestamps();
$table->index('request_id');
$table->index('course_id');
$table->index('user_id');
});
}
public function down(): void
{
Schema::dropIfExists('course_request_items');
}
};
@@ -0,0 +1,39 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('course_assignments', function (Blueprint $table) {
$table->id();
$table->foreignId('course_id')->constrained()->onDelete('cascade');
$table->foreignId('organization_id')->nullable()->constrained()->onDelete('cascade');
$table->foreignId('group_id')->nullable()->constrained()->onDelete('cascade');
$table->foreignId('user_id')->nullable()->constrained()->onDelete('cascade');
$table->enum('type', ['individual', 'group', 'organization'])->default('individual');
$table->date('start_date');
$table->date('end_date')->nullable();
$table->text('note')->nullable();
$table->foreignId('created_by')->nullable()->constrained('users')->onDelete('set null');
$table->boolean('is_active')->default(true);
$table->timestamps();
$table->index('course_id');
$table->index('organization_id');
$table->index('group_id');
$table->index('user_id');
$table->index('type');
$table->index('start_date');
$table->index('end_date');
});
}
public function down(): void
{
Schema::dropIfExists('course_assignments');
}
};
@@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('scorm_data', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->onDelete('cascade');
$table->foreignId('course_id')->constrained()->onDelete('cascade');
$table->string('package_id');
$table->string('sco_id');
$table->json('data');
$table->timestamp('last_access')->useCurrent();
$table->timestamps();
$table->index('user_id');
$table->index('course_id');
$table->index('package_id');
$table->index(['user_id', 'course_id', 'package_id']);
});
}
public function down(): void
{
Schema::dropIfExists('scorm_data');
}
};
@@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('user_course_progress', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->constrained()->onDelete('cascade');
$table->foreignId('course_id')->constrained()->onDelete('cascade');
$table->foreignId('module_id')->nullable()->constrained('course_modules')->onDelete('cascade');
$table->enum('status', ['not_started', 'in_progress', 'completed'])->default('not_started');
$table->integer('completion_percentage')->default(0);
$table->timestamp('started_at')->nullable();
$table->timestamp('completed_at')->nullable();
$table->timestamps();
$table->unique(['user_id', 'course_id', 'module_id']);
$table->index('user_id');
$table->index('course_id');
$table->index('status');
});
}
public function down(): void
{
Schema::dropIfExists('user_course_progress');
}
};
@@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('logs', function (Blueprint $table) {
$table->id();
$table->foreignId('user_id')->nullable()->constrained()->onDelete('set null');
$table->string('log_type');
$table->string('description');
$table->string('loggable_type')->nullable();
$table->unsignedBigInteger('loggable_id')->nullable();
$table->json('old_values')->nullable();
$table->json('new_values')->nullable();
$table->string('ip_address')->nullable();
$table->text('user_agent')->nullable();
$table->timestamps();
$table->index('user_id');
$table->index('log_type');
$table->index(['loggable_type', 'loggable_id']);
$table->index('created_at');
});
}
public function down(): void
{
Schema::dropIfExists('logs');
}
};
@@ -0,0 +1,22 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->foreign('organization_id')->references('id')->on('organizations')->onDelete('set null');
});
}
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
$table->dropForeign(['organization_id']);
});
}
};
@@ -0,0 +1,81 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('permissions', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('guard_name')->default('web');
$table->timestamps();
$table->unique(['name', 'guard_name']);
});
Schema::create('roles', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('guard_name')->default('web');
$table->timestamps();
$table->unique(['name', 'guard_name']);
});
Schema::create('model_has_permissions', function (Blueprint $table) {
$table->unsignedBigInteger('permission_id');
$table->string('model_type');
$table->unsignedBigInteger('model_id');
$table->foreign('permission_id')
->references('id')
->on('permissions')
->onDelete('cascade');
$table->primary(['permission_id', 'model_id', 'model_type'], 'model_has_permissions_permission_model_primary');
});
Schema::create('model_has_roles', function (Blueprint $table) {
$table->unsignedBigInteger('role_id');
$table->string('model_type');
$table->unsignedBigInteger('model_id');
$table->foreign('role_id')
->references('id')
->on('roles')
->onDelete('cascade');
$table->primary(['role_id', 'model_id', 'model_type'], 'model_has_roles_role_model_primary');
});
Schema::create('role_has_permissions', function (Blueprint $table) {
$table->unsignedBigInteger('permission_id');
$table->unsignedBigInteger('role_id');
$table->foreign('permission_id')
->references('id')
->on('permissions')
->onDelete('cascade');
$table->foreign('role_id')
->references('id')
->on('roles')
->onDelete('cascade');
$table->primary(['permission_id', 'role_id'], 'role_has_permissions_permission_role_primary');
});
}
public function down(): void
{
Schema::dropIfExists('role_has_permissions');
Schema::dropIfExists('model_has_roles');
Schema::dropIfExists('model_has_permissions');
Schema::dropIfExists('roles');
Schema::dropIfExists('permissions');
}
};
+16
View File
@@ -0,0 +1,16 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
public function run(): void
{
$this->call([
RoleSeeder::class,
UserSeeder::class,
]);
}
}
+92
View File
@@ -0,0 +1,92 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;
class RoleSeeder extends Seeder
{
public function run(): void
{
// Сброс кэша разрешений
app()[\Spatie\Permission\PermissionRegistrar::class]->forgetCachedPermissions();
// Создаем разрешения
$permissions = [
// Пользователи
'users.view',
'users.create',
'users.edit',
'users.delete',
// Организации
'organizations.view',
'organizations.create',
'organizations.edit',
'organizations.delete',
// Группы
'groups.view',
'groups.create',
'groups.edit',
'groups.delete',
// Курсы
'courses.view',
'courses.create',
'courses.edit',
'courses.delete',
'courses.publish',
// Тесты
'tests.view',
'tests.create',
'tests.edit',
'tests.delete',
// Назначения
'assignments.view',
'assignments.create',
'assignments.edit',
'assignments.delete',
// Заявки
'requests.view',
'requests.approve',
'requests.reject',
// Отчеты
'reports.view',
'reports.export',
// Откат результатов
'results.rollback',
// Системные настройки
'settings.manage',
];
foreach ($permissions as $permission) {
Permission::firstOrCreate(['name' => $permission]);
}
// Создаем роли
$adminRole = Role::firstOrCreate(['name' => 'Administrator']);
$adminRole->givePermissionTo(Permission::all());
$managerRole = Role::firstOrCreate(['name' => 'Manager']);
$managerRole->givePermissionTo(Permission::whereNotIn('name', ['settings.manage'])->get());
$curatorRole = Role::firstOrCreate(['name' => 'Curator']);
$curatorRole->givePermissionTo([
'users.view', 'users.create', 'users.edit',
'organizations.view',
'groups.view', 'groups.create', 'groups.edit',
'courses.view', 'courses.create', 'courses.edit',
'tests.view', 'tests.create', 'tests.edit',
'assignments.view', 'assignments.create', 'assignments.edit',
'requests.view', 'requests.approve', 'requests.reject',
'reports.view', 'reports.export',
'results.rollback',
]);
$studentRole = Role::firstOrCreate(['name' => 'Student']);
$studentRole->givePermissionTo([
'courses.view',
'tests.view',
]);
}
}
+75
View File
@@ -0,0 +1,75 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use App\Models\User;
use App\Models\Organization;
use Illuminate\Support\Facades\Hash;
class UserSeeder extends Seeder
{
public function run(): void
{
// Создаем администратора
$admin = User::firstOrCreate(
['email' => 'admin@lms.local'],
[
'name' => 'Администратор',
'password' => Hash::make('password'),
'email_verified_at' => now(),
]
);
$admin->assignRole('Administrator');
// Создаем менеджера
$manager = User::firstOrCreate(
['email' => 'manager@lms.local'],
[
'name' => 'Менеджер',
'password' => Hash::make('password'),
'email_verified_at' => now(),
]
);
$manager->assignRole('Manager');
// Создаем организацию
$organization = Organization::firstOrCreate(
['name' => 'Тестовая организация'],
[
'inn' => '1234567890',
'kpp' => '123456789',
'address' => 'г. Москва, ул. Тестовая, д. 1',
'phone' => '+7 (999) 123-45-67',
'email' => 'info@test-org.local',
'description' => 'Тестовая организация для демонстрации',
]
);
// Создаем куратора
$curator = User::firstOrCreate(
['email' => 'curator@lms.local'],
[
'name' => 'Куратор',
'password' => Hash::make('password'),
'email_verified_at' => now(),
'organization_id' => $organization->id,
]
);
$curator->assignRole('Curator');
// Создаем учащихся
for ($i = 1; $i <= 10; $i++) {
$student = User::firstOrCreate(
['email' => "student{$i}@lms.local"],
[
'name' => "Учащийся {$i}",
'password' => Hash::make('password'),
'email_verified_at' => now(),
'organization_id' => $i <= 5 ? $organization->id : null,
]
);
$student->assignRole('Student');
}
}
}