siakad-itm/app/Http/Requests/Admin/Users/LecturerRequest.php
Yoga Pangestu 07a00a92a2
Some checks failed
tests / ci (pull_request) Has been cancelled
Refactor lecturer management to support multiple departments
- Updated LecturerController to load multiple departments for lecturers.
- Modified LecturerRequest to accept an array of department IDs instead of a single department ID.
- Changed Department model to establish a many-to-many relationship with Lecturer.
- Adjusted Lecturer model to reflect the new many-to-many relationship with Department.
- Updated LecturerService to handle multiple departments during creation and updates.
- Created LecturerFactory and StudentFactory for generating test data.
- Added a migration for the new lecturer_department pivot table.
- Refactored seeder classes to accommodate the new structure for lecturers and departments.
- Enhanced frontend components for creating and editing lecturers to support multiple department selection.
2026-08-30 12:18:13 +07:00

61 lines
1.7 KiB
PHP

<?php
namespace App\Http\Requests\Admin\Users;
use App\Enums\Gender;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class LecturerRequest extends FormRequest
{
public function authorize(): bool
{
return true;
}
public function rules(): array
{
$userId = $this->route('user')?->id;
return [
'username' => [
'required',
'string',
'max:20',
'min:5',
'alpha_dash',
$userId === null
? Rule::unique('users')
: Rule::unique('users')->ignore($userId),
],
'email' => [
'required',
'string',
'email',
'max:255',
$userId === null
? Rule::unique('users')
: Rule::unique('users')->ignore($userId),
],
// Profile
'full_name' => ['required', 'string', 'max:150'],
'phone_number' => ['required', 'string', 'max:20'],
'address' => ['required', 'string'],
'gender' => ['required', 'string', Rule::in(Gender::values())],
'birth_date' => ['required', 'date'],
'birth_place' => ['required', 'string', 'max:100'],
// Lecturer fields
'lecturer_number' => [
'required',
'string',
'max:20',
Rule::unique('lecturers')->ignore($userId, 'user_id'),
],
'department_ids' => ['required', 'array', 'min:1'],
'department_ids.*' => ['integer', Rule::exists('departments', 'id')],
];
}
}