mirror of
https://github.com/robonen/education-project.git
synced 2026-03-20 02:44:31 +00:00
Получение предметов и учеников класса, классов учителя
This commit is contained in:
@@ -51,7 +51,7 @@ class SchoolClassController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
//добавление, изменение классного руководителя
|
//добавление, изменение классного руководителя
|
||||||
public function addClassroomTeacher(SchoolClass $class, Request $request)
|
public function addTeacher(SchoolClass $class, Request $request)
|
||||||
{
|
{
|
||||||
$teacher = Teacher::findOrfail((int)$request->input('teacher_id'));
|
$teacher = Teacher::findOrfail((int)$request->input('teacher_id'));
|
||||||
$class->classroom_teacher = $teacher->id;
|
$class->classroom_teacher = $teacher->id;
|
||||||
@@ -59,4 +59,26 @@ class SchoolClassController extends Controller
|
|||||||
return response()->json(SchoolClass::find($class->id), 200);
|
return response()->json(SchoolClass::find($class->id), 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//получение всех учеников в классе
|
||||||
|
public function getStudents(SchoolClass $class)
|
||||||
|
{
|
||||||
|
$students = $class->students;
|
||||||
|
$studentsOnlyFIO = [];
|
||||||
|
foreach ($students as $student) {
|
||||||
|
array_push($studentsOnlyFIO, $student->only('id', 'name', 'surname', 'patronymic'));
|
||||||
|
}
|
||||||
|
return response()->json($studentsOnlyFIO, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
//получение всех предметов для класса
|
||||||
|
public function getSubjects(SchoolClass $class)
|
||||||
|
{
|
||||||
|
$subjects = $class->subjects;
|
||||||
|
$subjectExceptPivot = [];
|
||||||
|
foreach ($subjects as $subject) {
|
||||||
|
array_push($subjectExceptPivot, collect($subject)->except('pivot'));
|
||||||
|
}
|
||||||
|
return response()->json($subjectExceptPivot, 200);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,4 +44,14 @@ class TeacherController extends Controller
|
|||||||
$teacher->update($request->all());
|
$teacher->update($request->all());
|
||||||
return response()->json($teacher, 200);
|
return response()->json($teacher, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getClasses(Teacher $teacher)
|
||||||
|
{
|
||||||
|
$timetables = $teacher->timetables;
|
||||||
|
$classes = [];
|
||||||
|
foreach ($timetables as $timetable) {
|
||||||
|
array_push($classes, $timetable->schoolClass->only('id','number','letter'));
|
||||||
|
}
|
||||||
|
return response()->json(collect($classes)->unique(), 200);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,12 +17,13 @@ class SchoolClass extends Model
|
|||||||
|
|
||||||
public function students()
|
public function students()
|
||||||
{
|
{
|
||||||
return $this->hasMany(Student::class);
|
return $this->hasMany(Student::class, 'class_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function subjects()
|
public function subjects()
|
||||||
{
|
{
|
||||||
return $this->belongsToMany(Subject::class, 'academic_plans')->withPivot('hours_per_week', 'hours_per_year');
|
return $this->belongsToMany(Subject::class, 'academic_plans', 'class_id')
|
||||||
|
->withPivot('hours_per_week', 'hours_per_year');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ class Subject extends Model
|
|||||||
|
|
||||||
public function schoolClasses()
|
public function schoolClasses()
|
||||||
{
|
{
|
||||||
return $this->belongsToMany(SchoolClass::class, 'academic_plans')->withPivot('hours_per_week', 'hours_per_year');
|
return $this->belongsToMany(SchoolClass::class, 'academic_plans', 'class_id')
|
||||||
|
->withPivot('hours_per_week', 'hours_per_year');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,4 +19,9 @@ class Teacher extends Model
|
|||||||
return $this->hasOne(SchoolClass::class, 'classroom_teacher');
|
return $this->hasOne(SchoolClass::class, 'classroom_teacher');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function timetables()
|
||||||
|
{
|
||||||
|
return $this->hasMany(Timetable::class);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class CreateTeachersTable extends Migration
|
|||||||
{
|
{
|
||||||
Schema::create('teachers', function (Blueprint $table) {
|
Schema::create('teachers', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->unsignedBigInteger('user_id');
|
$table->unsignedBigInteger('user_id')->unique();
|
||||||
$table->string('photo')->nullable();
|
$table->string('photo')->nullable();
|
||||||
$table->string('name')->nullable();
|
$table->string('name')->nullable();
|
||||||
$table->string('surname')->nullable();
|
$table->string('surname')->nullable();
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class CreateParentsTable extends Migration
|
|||||||
{
|
{
|
||||||
Schema::create('parents', function (Blueprint $table) {
|
Schema::create('parents', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->unsignedBigInteger('user_id');
|
$table->unsignedBigInteger('user_id')->unique();
|
||||||
$table->string('photo')->nullable();
|
$table->string('photo')->nullable();
|
||||||
$table->string('name')->nullable();
|
$table->string('name')->nullable();
|
||||||
$table->string('surname')->nullable();
|
$table->string('surname')->nullable();
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class CreateStudentsTable extends Migration
|
|||||||
{
|
{
|
||||||
Schema::create('students', function (Blueprint $table) {
|
Schema::create('students', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->unsignedBigInteger('user_id');
|
$table->unsignedBigInteger('user_id')->unique();
|
||||||
$table->string('photo')->nullable();
|
$table->string('photo')->nullable();
|
||||||
$table->string('name')->nullable();
|
$table->string('name')->nullable();
|
||||||
$table->string('surname')->nullable();
|
$table->string('surname')->nullable();
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class CreateHeadTeachersTable extends Migration
|
|||||||
{
|
{
|
||||||
Schema::create('head_teachers', function (Blueprint $table) {
|
Schema::create('head_teachers', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->unsignedBigInteger('user_id');
|
$table->unsignedBigInteger('user_id')->unique();
|
||||||
$table->string('photo')->nullable();
|
$table->string('photo')->nullable();
|
||||||
$table->string('name')->nullable();
|
$table->string('name')->nullable();
|
||||||
$table->string('surname')->nullable();
|
$table->string('surname')->nullable();
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ Route::group(['prefix' => 'auth'], function () {
|
|||||||
Route::apiResource('headteachers', 'Users\HeadTeacherController');
|
Route::apiResource('headteachers', 'Users\HeadTeacherController');
|
||||||
|
|
||||||
Route::apiResource('teachers', 'Users\TeacherController');
|
Route::apiResource('teachers', 'Users\TeacherController');
|
||||||
|
Route::get('teacher/{teacher}/classes', 'Users\TeacherController@getClasses');
|
||||||
|
|
||||||
Route::apiResource('students', 'Users\StudentController');
|
Route::apiResource('students', 'Users\StudentController');
|
||||||
|
|
||||||
@@ -20,7 +21,9 @@ Route::apiResource('parents', 'Users\ParenttController');
|
|||||||
Route::apiResource('subjects', 'SubjectController');
|
Route::apiResource('subjects', 'SubjectController');
|
||||||
|
|
||||||
Route::apiResource('classes', 'SchoolClassController');
|
Route::apiResource('classes', 'SchoolClassController');
|
||||||
Route::post('classes/{class}/teacher', 'SchoolClassController@addClassroomTeacher');
|
Route::post('classes/{class}/teacher', 'SchoolClassController@addTeacher');
|
||||||
|
Route::get('classes/{class}/students', 'SchoolClassController@getStudents');
|
||||||
|
Route::get('classes/{class}/subjects', 'SchoolClassController@getSubjects');
|
||||||
|
|
||||||
Route::apiResource('themes', 'ThemeController');
|
Route::apiResource('themes', 'ThemeController');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user